Skip to content

[Fix] Remove Blooming Cache#143

Merged
char-yb merged 1 commit intodevelopfrom
fix/blooming-cache
Apr 1, 2026
Merged

[Fix] Remove Blooming Cache#143
char-yb merged 1 commit intodevelopfrom
fix/blooming-cache

Conversation

@char-yb
Copy link
Copy Markdown
Member

@char-yb char-yb commented Apr 1, 2026

🌱 관련 이슈

  • close #

📌 작업 내용 및 특이 사항

  • 개화 상태 캐시 로직 삭제.
  • 자주 변경되는 데이터 사항이라 오히려 캐시 연산의 비용이 더 큰 걸로 보아 삭제

📝 참고

CREATE INDEX CONCURRENTLY idx_blooming_flower_event_id_created_at
ON t_blooming (flower_event_id, created_at);

CREATE INDEX CONCURRENTLY idx_blooming_flower_spot_cafe_id_created_at
ON t_blooming (flower_spot_cafe_id, created_at);

추후 개화 상태 테이블에 cafe와 event에 대한 데이터가 급증 시 해당 인덱스 추가할 계획

📌 체크 리스트

  • 리뷰어를 추가하셨나요 ?
  • 변경사항에 대해 충분히 설명하고 있나요 ?

Summary by CodeRabbit

  • Refactor

    • Optimized recently blooming query operations by streamlining internal architecture and improving handling of batch requests with duplicate IDs.
  • Tests

    • Added test coverage for batch bloom query operations to verify deduplication and correct lookup behavior.

@char-yb char-yb self-assigned this Apr 1, 2026
@char-yb char-yb requested a review from LeeHanEum as a code owner April 1, 2026 15:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

📝 Walkthrough

Walkthrough

This PR converts three batch query methods for recently-blooming data from synchronous to asynchronous (suspend) functions across the Blooming domain layer. It removes caching infrastructure from BloomingService, adds ID deduplication logic, and updates repository implementations to use coroutine-based transaction handling.

Changes

Cohort / File(s) Summary
Core Domain Interfaces
pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingRepository.kt, pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingFinder.kt
Converted findRecentBySpotIds, findRecentByEventIds, and findRecentByCafeIds methods to suspend functions across both the interface and implementation.
Service Layer
pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingService.kt
Removed CacheRepository dependency, converted bulk query methods to suspend functions, added distinct() call for ID deduplication, and removed internal cache management logic and eviction routines.
Database Layer
pida-storage/db-core/src/main/kotlin/com/pida/storage/db/core/blooming/BloomingCoreRepository.kt
Updated method implementations to use suspend signatures and changed transaction context from Tx.readable to Tx.coReadable.
Tests
pida-core/core-domain/src/test/kotlin/com/pida/blooming/BloomingServiceTest.kt
Removed CacheRepository from test setup and added three new tests verifying deduplication behavior for recentlyBloomingBySpotIds, recentlyBloomingByEventIds, and recentlyBloomingByCafeIds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 No more cache delays, just suspend and await,
Async bloomings query at a faster rate!
Distinct IDs deduplicate with grace,
Coroutines now handle the Blooming race. 🌸

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[Fix] Remove Blooming Cache' is directly related to the main change—removing blooming cache logic and dependencies across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/blooming-cache

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@pida-core/core-domain/src/test/kotlin/com/pida/blooming/BloomingServiceTest.kt`:
- Around line 45-124: Tests calling suspend methods recentlyBloomingBySpotIds,
recentlyBloomingByEventIds, and recentlyBloomingByCafeIds must run in a
coroutine test scope and use MockK's coroutine stubs/verifications: wrap each
test body in kotlinx.coroutines.test.runTest and replace every/verify with
coEvery/coVerify when stubbing/verifying
bloomingFinder.recentlyBloomingBySpotIds,
bloomingFinder.recentlyBloomingByEventIds, and
bloomingFinder.recentlyBloomingByCafeIds respectively so the suspend
interactions are executed and asserted correctly.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2d41fac1-297e-4725-bb35-2e28d38b0934

📥 Commits

Reviewing files that changed from the base of the PR and between 74461ac and 52cad83.

📒 Files selected for processing (5)
  • pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingFinder.kt
  • pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingRepository.kt
  • pida-core/core-domain/src/main/kotlin/com/pida/blooming/BloomingService.kt
  • pida-core/core-domain/src/test/kotlin/com/pida/blooming/BloomingServiceTest.kt
  • pida-storage/db-core/src/main/kotlin/com/pida/storage/db/core/blooming/BloomingCoreRepository.kt

Comment on lines +45 to +124
@Test
fun `spot batch 조회는 중복 id를 제거한 뒤 한 번의 finder 호출로 위임한다`() {
val bloomingAppender = mockk<BloomingAppender>()
val bloomingValidator = mockk<BloomingValidator>()
val bloomingFinder = mockk<BloomingFinder>()
val service = BloomingService(bloomingAppender, bloomingValidator, bloomingFinder)
val bloomings =
listOf(
Blooming(
id = 1L,
status = BloomingStatus.BLOOMED,
userId = 10L,
flowerSpotId = 30L,
flowerEventId = null,
flowerSpotCafeId = null,
createdAt = LocalDateTime.of(2026, 4, 1, 9, 0),
),
)

every { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) } returns bloomings

val result = service.recentlyBloomingBySpotIds(listOf(30L, 31L, 30L))

result shouldBe bloomings
verify(exactly = 1) { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) }
}

@Test
fun `event batch 조회는 중복 id를 제거한 뒤 한 번의 finder 호출로 위임한다`() {
val bloomingAppender = mockk<BloomingAppender>()
val bloomingValidator = mockk<BloomingValidator>()
val bloomingFinder = mockk<BloomingFinder>()
val service = BloomingService(bloomingAppender, bloomingValidator, bloomingFinder)
val bloomings =
listOf(
Blooming(
id = 2L,
status = BloomingStatus.LITTLE,
userId = 11L,
flowerSpotId = null,
flowerEventId = 40L,
flowerSpotCafeId = null,
createdAt = LocalDateTime.of(2026, 4, 1, 10, 0),
),
)

every { bloomingFinder.recentlyBloomingByEventIds(listOf(40L, 41L)) } returns bloomings

val result = service.recentlyBloomingByEventIds(listOf(40L, 41L, 40L))

result shouldBe bloomings
verify(exactly = 1) { bloomingFinder.recentlyBloomingByEventIds(listOf(40L, 41L)) }
}

@Test
fun `cafe batch 조회는 중복 id를 제거한 뒤 한 번의 finder 호출로 위임한다`() {
val bloomingAppender = mockk<BloomingAppender>()
val bloomingValidator = mockk<BloomingValidator>()
val bloomingFinder = mockk<BloomingFinder>()
val service = BloomingService(bloomingAppender, bloomingValidator, bloomingFinder)
val bloomings =
listOf(
Blooming(
id = 3L,
status = BloomingStatus.WITHERED,
userId = 12L,
flowerSpotId = null,
flowerEventId = null,
flowerSpotCafeId = 50L,
createdAt = LocalDateTime.of(2026, 4, 1, 11, 0),
),
)

every { bloomingFinder.recentlyBloomingByCafeIds(listOf(50L, 51L)) } returns bloomings

val result = service.recentlyBloomingByCafeIds(listOf(50L, 51L, 50L))

result shouldBe bloomings
verify(exactly = 1) { bloomingFinder.recentlyBloomingByCafeIds(listOf(50L, 51L)) }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify coroutine-test usage and MockK coroutine DSL for new batch tests.
target="pida-core/core-domain/src/test/kotlin/com/pida/blooming/BloomingServiceTest.kt"

echo "[1] New batch tests declared without runTest:"
rg -nP 'fun `.*batch 조회.*`\(\)\s*\{' "$target"

echo "[2] Suspend finder stubs using every (should be coEvery):"
rg -nP 'every \{ bloomingFinder\.recentlyBloomingBy(Spot|Event|Cafe)Ids' "$target"

echo "[3] Suspend finder verifies using verify (should be coVerify):"
rg -nP 'verify\(exactly\s*=\s*1\)\s*\{ bloomingFinder\.recentlyBloomingBy(Spot|Event|Cafe)Ids' "$target"

echo "[4] Presence of coroutine-test constructs:"
rg -nP 'runTest|coEvery|coVerify' "$target"

Repository: Team-PIDA/Pida-Server

Length of output: 1054


Suspend test calls need coroutine test scope and MockK coroutine DSL.

The three batch test functions (lines 46, 73, 100) invoke suspend service methods without wrapping in runTest. Additionally, suspend finder methods are stubbed and verified with every/verify instead of coEvery/coVerify.

🔧 Proposed fix pattern (apply to all three batch tests)
+import io.mockk.coEvery
+import io.mockk.coVerify
+import kotlinx.coroutines.test.runTest
@@
-    fun `spot batch 조회는 중복 id를 제거한 뒤 한 번의 finder 호출로 위임한다`() {
+    fun `spot batch 조회는 중복 id를 제거한 뒤 한 번의 finder 호출로 위임한다`() = runTest {
@@
-        every { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) } returns bloomings
+        coEvery { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) } returns bloomings
@@
-        verify(exactly = 1) { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) }
+        coVerify(exactly = 1) { bloomingFinder.recentlyBloomingBySpotIds(listOf(30L, 31L)) }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@pida-core/core-domain/src/test/kotlin/com/pida/blooming/BloomingServiceTest.kt`
around lines 45 - 124, Tests calling suspend methods recentlyBloomingBySpotIds,
recentlyBloomingByEventIds, and recentlyBloomingByCafeIds must run in a
coroutine test scope and use MockK's coroutine stubs/verifications: wrap each
test body in kotlinx.coroutines.test.runTest and replace every/verify with
coEvery/coVerify when stubbing/verifying
bloomingFinder.recentlyBloomingBySpotIds,
bloomingFinder.recentlyBloomingByEventIds, and
bloomingFinder.recentlyBloomingByCafeIds respectively so the suspend
interactions are executed and asserted correctly.

@char-yb char-yb merged commit 44fa32e into develop Apr 1, 2026
2 checks passed
@char-yb char-yb deleted the fix/blooming-cache branch April 6, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant