Skip to content

Fixed some pointless drops list N+1 queries#2380

Merged
GelatoGenesis merged 2 commits into
mainfrom
b-17786664563
May 13, 2026
Merged

Fixed some pointless drops list N+1 queries#2380
GelatoGenesis merged 2 commits into
mainfrom
b-17786664563

Conversation

@GelatoGenesis
Copy link
Copy Markdown
Collaborator

@GelatoGenesis GelatoGenesis commented May 13, 2026

Summary by CodeRabbit

  • Tests

    • Updated test fixtures and assertions for wave messages and drop APIs to align with v2 API contract and endpoints
    • Expanded test coverage for drop enrichment behavior, including selective metadata and rater hydration
  • Improvements

    • Enhanced drop fetching operations with configurable options to control metadata and top-rater data hydration

Review Change Stack

Signed-off-by: GelatoGenesis <tarmokalling@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

📝 Walkthrough

Walkthrough

Production code adds optional includeFullMetadata flags to the drop enrichment pipeline, allowing callers to choose between full or priority-only metadata hydration. Tests expand coverage for list endpoint behavior with shared fixtures and helper utilities, and wave-messages utility tests migrate to V2 API shapes and endpoints.

Changes

V2 API Hydration Control and Test Coverage

Layer / File(s) Summary
V2 API Hydration Control Implementation
services/api/wave-drops-v2-api.ts
fetchDropMetadataV2, hydrateDropV2, hydrateDropsV2, and fetchDropV2ById now accept includeFullMetadata flag (default true for single-drop fetches, false for batch/list operations) to control whether full metadata is fetched or only priority metadata returned.
Wave-drops V2 API Test Infrastructure
__tests__/services/api/wave-drops-v2-api.test.ts
Shared test fixtures (priorityMetadata, createEnrichableDrop, waveMin) and expectNoListEnrichmentCalls helper established to validate consistent enrichment-skipping behavior across list endpoints.
Wave-drops V2 API List and Single-drop Endpoint Tests
__tests__/services/api/wave-drops-v2-api.test.ts
New test suites for fetchWaveDropsFeedV2, fetchDropRepliesV2, fetchBoostedDropsV2, and fetchDropV2ById validate that list endpoints skip full metadata/top-rater enrichment while exposing priority metadata and empty top-raters; single-drop fetch confirms metadata hydration without top-raters when includeTopRaters: false.
Wave-messages Utilities V2 Test Migration
__tests__/contexts/wave/utils/wave-messages-utils.test.ts, __tests__/contexts/wave/utils/wave-messages-utils.additional.test.ts
Test fixtures updated to use V2 shapes (sampleIdentity, sampleWaveOverview, sampleV2Drop); mock endpoints changed to v2/waves/w/drops; fuller mock drop and wave objects replace minimal shapes; test assertions use looser matching with expect.objectContaining.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ragnep
  • simo6529

Poem

A rabbit hops through metadata lands,
Where includeFullMetadata wisely expands—
List feeds stay light, full drops shine bright,
V2 shapes now dance in tests just right! 🐰✨

🚥 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 accurately describes the main change: eliminating N+1 queries in drops list operations by adding includeFullMetadata and includeTopRaters flags to skip unnecessary hydration.
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-17786664563

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.

🧹 Nitpick comments (1)
__tests__/services/api/wave-drops-v2-api.test.ts (1)

397-419: ⚡ Quick win

Add an explicit includeFullMetadata: false detail-path test.

fetchDropV2ById now accepts includeFullMetadata, but this suite only verifies the default metadata-on behavior. A focused false-path assertion would lock in the N+1 optimization and prevent regressions.

Proposed test addition
+  it("skips full metadata fetch for single drop details when includeFullMetadata is false", async () => {
+    commonApiFetchMock.mockResolvedValueOnce({
+      wave,
+      drop: createEnrichableDrop(),
+    });
+
+    const result = await fetchDropV2ById("drop-1", undefined, {
+      includeFullMetadata: false,
+      includeTopRaters: false,
+    });
+
+    expect(commonApiFetchMock).toHaveBeenCalledTimes(1);
+    expect(commonApiFetchMock).not.toHaveBeenCalledWith(
+      expect.objectContaining({
+        endpoint: expect.stringContaining("/metadata"),
+      })
+    );
+    expect(result.metadata).toEqual(priorityMetadata);
+  });
🤖 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__/services/api/wave-drops-v2-api.test.ts` around lines 397 - 419, Add
a focused test case for the false-path of includeFullMetadata: call
fetchDropV2ById("drop-1", undefined, { includeFullMetadata: false,
includeTopRaters: false }) and assert that commonApiFetchMock is NOT called with
the "v2/drops/drop-1/metadata" endpoint (and only the primary "v2/drops/drop-1"
call is made), and that the returned result.metadata equals only the
priorityMetadata (not fullMetadata) and result.top_raters is [] to lock in the
N+1 optimization; reference the existing test structure around fetchDropV2ById
and expectations on commonApiFetchMock and result.metadata/top_raters to mirror
assertions.
🤖 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.

Nitpick comments:
In `@__tests__/services/api/wave-drops-v2-api.test.ts`:
- Around line 397-419: Add a focused test case for the false-path of
includeFullMetadata: call fetchDropV2ById("drop-1", undefined, {
includeFullMetadata: false, includeTopRaters: false }) and assert that
commonApiFetchMock is NOT called with the "v2/drops/drop-1/metadata" endpoint
(and only the primary "v2/drops/drop-1" call is made), and that the returned
result.metadata equals only the priorityMetadata (not fullMetadata) and
result.top_raters is [] to lock in the N+1 optimization; reference the existing
test structure around fetchDropV2ById and expectations on commonApiFetchMock and
result.metadata/top_raters to mirror assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a4c46d9-5acc-4a70-9710-adf3ac227604

📥 Commits

Reviewing files that changed from the base of the PR and between f1792cb and 1ed2479.

📒 Files selected for processing (4)
  • __tests__/contexts/wave/utils/wave-messages-utils.additional.test.ts
  • __tests__/contexts/wave/utils/wave-messages-utils.test.ts
  • __tests__/services/api/wave-drops-v2-api.test.ts
  • services/api/wave-drops-v2-api.ts

@sonarqubecloud
Copy link
Copy Markdown

@GelatoGenesis GelatoGenesis merged commit 3f40352 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