Add admin retrospect creation cycle average API#468
Conversation
개요이 PR은 회고 생성 주기의 평균 시간을 계산하고 조회하는 새로운 관리자 엔드포인트를 추가합니다. 날짜 범위 내 이벤트 타임스탬프를 쿼리하고 연속된 이벤트 간의 간격을 평균하여 전체, 팀, 개별 회고의 생성 주기 평균을 반환합니다. 변경사항회고 생성 주기 평균 조회 기능
예상 코드 리뷰 노력🎯 2 (Simple) | ⏱️ ~10분 시
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@layer-admin/src/main/java/org/layer/admin/retrospect/repository/AdminRetrospectHistoryRepository.java`:
- Around line 36-46: The JOIN in
AdminRetrospectHistoryRepository.findEventTimesBetweenBySpaceCategory can
produce duplicate or temporally incorrect matches because it joins only on
spaceId; update the query to match the AdminSpaceHistory row that reflects the
space's category at the retrospective eventTime (e.g., add "AND s.eventTime <=
r.eventTime" and choose the latest s.eventTime per space prior to r.eventTime
via a subquery or window function), and/or apply DISTINCT to the selected
r.eventTime to avoid duplicates; locate the query string in
AdminRetrospectHistoryRepository and modify it to enforce s.eventTime <=
r.eventTime and select the most recent AdminSpaceHistory record per spaceId
before r.eventTime (or add DISTINCT) so results are temporally accurate and
deduplicated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c4ed1134-5de7-4374-aa36-9ec7e6ab49d6
📒 Files selected for processing (4)
layer-admin/src/main/java/org/layer/admin/retrospect/controller/AdminRetrospectController.javalayer-admin/src/main/java/org/layer/admin/retrospect/controller/dto/RetrospectCreationCycleAverageResponse.javalayer-admin/src/main/java/org/layer/admin/retrospect/repository/AdminRetrospectHistoryRepository.javalayer-admin/src/main/java/org/layer/admin/retrospect/service/AdminRetrospectService.java
| @Query("SELECT r.eventTime " + | ||
| "FROM AdminRetrospectHistory r " + | ||
| "JOIN AdminSpaceHistory s ON r.spaceId = s.spaceId " + | ||
| "WHERE r.eventTime BETWEEN :startTime AND :endTime " + | ||
| "AND s.category = :category " + | ||
| "ORDER BY r.eventTime ASC") | ||
| List<LocalDateTime> findEventTimesBetweenBySpaceCategory( | ||
| @Param("startTime") LocalDateTime startTime, | ||
| @Param("endTime") LocalDateTime endTime, | ||
| @Param("category") AdminSpaceCategory category | ||
| ); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# AdminSpaceHistory 엔티티 구조 및 spaceId 중복 여부 확인
# AdminSpaceHistory 엔티티 클래스 찾기
fd -e java AdminSpaceHistory
# AdminSpaceHistory의 필드와 관계 확인
rg -A 20 'class AdminSpaceHistory' --type java
# spaceId를 기준으로 그룹화하는 다른 쿼리가 있는지 확인 (중복 처리 패턴 파악)
rg -n 'AdminSpaceHistory.*spaceId' --type java -C 3Repository: depromeet/layer-server
Length of output: 3104
🏁 Script executed:
# Check AdminRetrospectHistory entity structure
fd -e java AdminRetrospectHistory | head -5
# Get full AdminRetrospectHistory class
rg -A 30 'class AdminRetrospectHistory' --type java -m 1
# Check other queries in the repository that use AdminSpaceHistory to understand patterns
rg 'JOIN AdminSpaceHistory|FROM AdminSpaceHistory' --type java -B 3 -A 8Repository: depromeet/layer-server
Length of output: 7401
🏁 Script executed:
# Check if there are unique constraints or indexes on spaceId in AdminSpaceHistory
rg '@Unique|@Index|@Column.*unique' layer-admin/src/main/java/org/layer/admin/space/entity/AdminSpaceHistory.java
# Check the full AdminSpaceHistory entity to see all fields and constraints
cat -n layer-admin/src/main/java/org/layer/admin/space/entity/AdminSpaceHistory.java
# Check if there are tests using this method to understand expected behavior
rg 'findEventTimesBetweenBySpaceCategory' --type java -B 3 -A 5Repository: depromeet/layer-server
Length of output: 4772
JOIN 쿼리의 정확성 문제를 확인했습니다.
spaceId 기반 JOIN이 잠재적으로 잘못된 결과를 생성할 수 있습니다:
-
중복 문제:
AdminSpaceHistory에spaceId에 대한 유니크 제약이 없어, 동일한spaceId에 여러 레코드가 존재할 수 있습니다. 이 경우 JOIN 결과로 동일한eventTime이 중복 반환됩니다. -
시간적 정확성 부재: 현재 쿼리는
AdminSpaceHistory에 시간 필터가 없어, 회고 생성 시점(r.eventTime)의 스페이스 카테고리를 반영하지 않습니다. 스페이스 카테고리가 변경된 경우, 잘못된 카테고리로 분류될 수 있습니다. -
데이터 무결성:
spaceId만으로 JOIN하면 과거에 변경된 다른 카테고리 상태까지 모두 매칭되어, 의도하지 않은 데이터 포함으로 통계 계산이 부정확해질 수 있습니다.
해결 방안:
DISTINCT를 추가하거나AND s.eventTime <= r.eventTime조건으로 회고 생성 시점의 카테고리만 매칭하거나- 필요에 따라 가장 최근의 스페이스 상태만 선택하도록 수정해야 합니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@layer-admin/src/main/java/org/layer/admin/retrospect/repository/AdminRetrospectHistoryRepository.java`
around lines 36 - 46, The JOIN in
AdminRetrospectHistoryRepository.findEventTimesBetweenBySpaceCategory can
produce duplicate or temporally incorrect matches because it joins only on
spaceId; update the query to match the AdminSpaceHistory row that reflects the
space's category at the retrospective eventTime (e.g., add "AND s.eventTime <=
r.eventTime" and choose the latest s.eventTime per space prior to r.eventTime
via a subquery or window function), and/or apply DISTINCT to the selected
r.eventTime to avoid duplicates; locate the query string in
AdminRetrospectHistoryRepository and modify it to enforce s.eventTime <=
r.eventTime and select the most recent AdminSpaceHistory record per spaceId
before r.eventTime (or add DISTINCT) so results are temporally accurate and
deduplicated.
Motivation
Description
GET /admin/retrospect/creation-cycle-averagewired toAdminRetrospectService#getRetrospectCreationCycleAverage.RetrospectCreationCycleAverageResponsewithtotalAverageSeconds,teamRetrospectAverageSeconds, andindividualRetrospectAverageSecondsfields.findEventTimesBetweenandfindEventTimesBetweenBySpaceCategorytoAdminRetrospectHistoryRepositoryto fetch ordered creation timestamps overall and filtered byAdminSpaceCategory.calculateAverageCreationCycleSeconds) and return per-category and overall averages.Testing
git diff --checkwhich reported no issues../gradlew :layer-admin:compileJavabut it failed in this environment due to an initial JDK classfile/version mismatch (Unsupported class file major version 69).JAVA_HOME=/root/.local/share/mise/installs/java/17.0.2 ./gradlew :layer-admin:compileJavaand--offline, both of which failed because the Gradle Spring Boot plugin (org.springframework.boot:3.3.1) could not be resolved in the current environment or local cache.Codex Task
Summary by CodeRabbit
새로운 기능