Skip to content

Fixed some pointless drops list N+1 queries#2384

Merged
GelatoGenesis merged 1 commit into
mainfrom
b-17786737983
May 13, 2026
Merged

Fixed some pointless drops list N+1 queries#2384
GelatoGenesis merged 1 commit into
mainfrom
b-17786737983

Conversation

@GelatoGenesis
Copy link
Copy Markdown
Collaborator

@GelatoGenesis GelatoGenesis commented May 13, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Prevented stale or incorrect quoted-drop data during transitions so quoted content updates reliably.
  • Performance Improvements

    • Loads drop metadata only when possible to reduce full-data fetches and speed up rendering.
    • Reuses cached or derived drop data to avoid unnecessary network requests.
  • UX

    • Quoted drops now receive wave context to improve quote resolution and consistency.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b360d25-8873-418b-ae6f-a730c7accee2

📥 Commits

Reviewing files that changed from the base of the PR and between 6ea3cea and ce039a9.

📒 Files selected for processing (10)
  • __tests__/components/waves/drop/useSingleWaveDropData.test.tsx
  • __tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx
  • __tests__/services/api/drop-api.test.ts
  • __tests__/services/api/wave-drops-v2-api.test.ts
  • components/drops/view/part/dropPartMarkdown/renderers.tsx
  • components/waves/drop/useSingleWaveDropData.ts
  • components/waves/drops/WaveDropPartContentMarkdown.tsx
  • components/waves/drops/WaveDropQuoteWithDropId.tsx
  • services/api/drop-api.ts
  • services/api/wave-drops-v2-api.ts
✅ Files skipped from review due to trivial changes (1)
  • components/drops/view/part/dropPartMarkdown/renderers.tsx
🚧 Files skipped from review as they are similar to previous changes (9)
  • components/waves/drops/WaveDropPartContentMarkdown.tsx
  • tests/services/api/drop-api.test.ts
  • services/api/drop-api.ts
  • tests/services/api/wave-drops-v2-api.test.ts
  • services/api/wave-drops-v2-api.ts
  • components/waves/drop/useSingleWaveDropData.ts
  • tests/components/waves/drop/useSingleWaveDropData.test.tsx
  • components/waves/drops/WaveDropQuoteWithDropId.tsx
  • tests/components/waves/drops/WaveDropQuoteWithDropId.test.tsx

📝 Walkthrough

Walkthrough

This PR refactors drop hydration to fetch only metadata where possible, adds a metadata-only API helper, updates the single-drop hook to merge metadata into initial drops, and makes the drop-quote component use waveId and cached/derived initialDrop to avoid unnecessary queries.

Changes

Drop metadata-only hydration architecture

Layer / File(s) Summary
Wave-drops-v2 API: metadata-only function and lean hydration defaults
services/api/wave-drops-v2-api.ts, __tests__/services/api/wave-drops-v2-api.test.ts
New exported fetchDropMetadataByIdV2 fetches v2 drop metadata by ID and merges with priority metadata; fetchDropMetadataV2 delegates to it; mergeMetadata uses readonly arrays; fetchDropV2ById applies explicit false defaults for includeFullMetadata and includeTopRaters.
Drop API refactoring for explicit lean hydration
services/api/drop-api.ts, __tests__/services/api/drop-api.test.ts
fetchDropResultsByIds now calls fetchDropV2ById with explicit options { includeFullMetadata: false, includeTopRaters: false } for batched/lean requests.
Single-drop hook metadata-only hydration
components/waves/drop/useSingleWaveDropData.ts, __tests__/components/waves/drop/useSingleWaveDropData.test.tsx
useSingleWaveDropData fetches only metadata via fetchDropMetadataByIdV2, derives waveId from initialDrop.wave.id, merges hydrated metadata into initialDrop to produce drop, and unconditionally computes extendedDrop.
Drop quote component with waveId and smart initialDrop derivation
components/waves/drops/WaveDropQuoteWithDropId.tsx, __tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx
Accepts optional waveId prop, reads cached ApiDrop via useQueryClient().getQueryData, derives a full drop from wave messages via useMyStreamOptional, computes initialDrop from maybeDrop/cache/wave-store in priority order, disables useQuery when initialDrop exists and uses it as initialData.
Wire waveId through drop quote rendering paths
components/drops/view/part/dropPartMarkdown/renderers.tsx, components/waves/drops/WaveDropPartContentMarkdown.tsx
Pass waveId to WaveDropQuoteWithDropId from rendering paths so the component can use wave context to derive initialDrop.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ragnep
  • prxt6529

Poem

🐰 In metadata meadows I lightly tread,
I fetch just the titles and leave the rest fed,
Quotes skip the fetch when cache is near,
Waves whisper drops the rabbit can hear,
Lean hydration hops — light-footed and glad.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main objective: fixing N+1 query issues in drops list operations, which aligns with the core refactoring to use metadata-only fetching instead of full drop details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 b-17786737983

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

@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: 2

🧹 Nitpick comments (1)
__tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx (1)

74-97: ⚡ Quick win

Add a test for mismatched maybeDrop.id vs dropId.

Current cases don’t cover the scenario where maybeDrop exists but refers to a different drop. Add one assertion that fetch stays enabled and initialData is not set in that case.

Also applies to: 121-153

🤖 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 `@__tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx` around
lines 74 - 97, Add a new test case for WaveDropQuoteWithDropId where
maybeDrop.id does not match the passed dropId (e.g., maybeDrop.id = "d1" and
dropId = " d2 "), mocking useQuery the same way; assert that the useQuery call
for QueryKey.DROP has enabled === true (fetch stays enabled), that initialData
is not provided (call.initialData is undefined and no initialDataUpdatedAt
property), and that fetchDropByIdBatchedMock is allowed to be invoked (or has
been called) instead of being suppressed. Use the existing test pattern
(useQuery.mockImplementation, capturedProps, and examining
useQuery.mock.calls[0][0]) and reference maybeDrop, dropId, useQuery,
QueryKey.DROP, initialData, and fetchDropByIdBatchedMock to locate the relevant
code.
🤖 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 `@components/waves/drops/WaveDropQuoteWithDropId.tsx`:
- Around line 96-105: The bug is that maybeDrop is used unconditionally as
initialData and can mismatch normalizedDropId which causes skipping the fetch;
fix by only accepting maybeDrop when its id matches normalizedDropId (e.g.
compute initialDrop as (maybeDrop?.id === normalizedDropId ? maybeDrop :
cachedDrop ?? waveMessagesDrop ?? null) or similarly guard each cached source by
id) so that useQuery's enabled/initialData logic uses a drop that actually
matches normalizedDropId (affecting getDropQueryKey, enabled and initialData
passed to useQuery).

In `@services/api/wave-drops-v2-api.ts`:
- Around line 219-227: The catch block in fetchDropMetadataByIdV2 is currently
swallowing errors (including from getNormalizedDropId) by returning
priorityMetadata; update the catch so that after calling
rethrowAbortFetchError(error) it does not return a fallback but instead rethrows
the error (e.g., throw error) so invalid dropId or other unexpected errors
propagate to the caller; keep special handling for aborts via
rethrowAbortFetchError but do not return [...priorityMetadata] in the catch.
References: fetchDropMetadataByIdV2, getNormalizedDropId, getDropEndpointId,
commonApiFetch, mergeMetadata.

---

Nitpick comments:
In `@__tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx`:
- Around line 74-97: Add a new test case for WaveDropQuoteWithDropId where
maybeDrop.id does not match the passed dropId (e.g., maybeDrop.id = "d1" and
dropId = " d2 "), mocking useQuery the same way; assert that the useQuery call
for QueryKey.DROP has enabled === true (fetch stays enabled), that initialData
is not provided (call.initialData is undefined and no initialDataUpdatedAt
property), and that fetchDropByIdBatchedMock is allowed to be invoked (or has
been called) instead of being suppressed. Use the existing test pattern
(useQuery.mockImplementation, capturedProps, and examining
useQuery.mock.calls[0][0]) and reference maybeDrop, dropId, useQuery,
QueryKey.DROP, initialData, and fetchDropByIdBatchedMock to locate the relevant
code.
🪄 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: 56e745ba-1b71-47a1-a103-4bf3c7110755

📥 Commits

Reviewing files that changed from the base of the PR and between d89dc7f and 6ea3cea.

📒 Files selected for processing (10)
  • __tests__/components/waves/drop/useSingleWaveDropData.test.tsx
  • __tests__/components/waves/drops/WaveDropQuoteWithDropId.test.tsx
  • __tests__/services/api/drop-api.test.ts
  • __tests__/services/api/wave-drops-v2-api.test.ts
  • components/drops/view/part/dropPartMarkdown/renderers.tsx
  • components/waves/drop/useSingleWaveDropData.ts
  • components/waves/drops/WaveDropPartContentMarkdown.tsx
  • components/waves/drops/WaveDropQuoteWithDropId.tsx
  • services/api/drop-api.ts
  • services/api/wave-drops-v2-api.ts

Comment thread components/waves/drops/WaveDropQuoteWithDropId.tsx
Comment thread services/api/wave-drops-v2-api.ts
Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@GelatoGenesis GelatoGenesis merged commit c0977eb into main May 13, 2026
8 checks passed
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.

2 participants