Skip to content

Refactor Store#search to support FileDef and fix N+1 query issue#3955

Merged
lukemelia merged 4 commits intomainfrom
cs-10109-store-search-refactor
Feb 5, 2026
Merged

Refactor Store#search to support FileDef and fix N+1 query issue#3955
lukemelia merged 4 commits intomainfrom
cs-10109-store-search-refactor

Conversation

@lukemelia
Copy link
Contributor

@lukemelia lukemelia commented Feb 5, 2026

Summary

  • Make Store#search generic to support both CardDef and FileDef queries
  • Add { includeMeta: true } option to return pagination metadata alongside instances
  • Extract shared search logic into private fetchAndHydrateSearchResults method
  • Add _addResourceFromSearchData to hydrate resources directly from search response data without making individual network requests (fixes N+1 query problem)
  • Simplify SearchResource to delegate to Store#search instead of duplicating fetch/hydrate logic
  • Remove ~95 lines of duplicated code between SearchResource and Store

Test plan

  • Existing search tests pass

🤖 Generated with Claude Code

- Make Store#search generic to support both CardDef and FileDef queries
- Add { includeMeta: true } option to return pagination metadata
- Extract shared search logic into private fetchAndHydrateSearchResults
- Add _addResourceFromSearchData to hydrate resources from search response
  without making individual network requests (fixes N+1 query problem)
- Simplify SearchResource to delegate to Store#search
- Remove code duplication between SearchResource and Store

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Preview deployments

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors the Store#search method to support generic types for both CardDef and FileDef queries, adds an option to include pagination metadata, and fixes an N+1 query issue. The changes consolidate approximately 95 lines of duplicated code between Store and SearchResource.

Changes:

  • Made Store#search generic to support both CardDef and FileDef queries with proper type overloads
  • Added { includeMeta: true } option to return pagination metadata alongside instances
  • Extracted shared search logic into fetchAndHydrateSearchResults private method and added _addResourceFromSearchData to hydrate resources directly from search response data, eliminating N+1 queries
  • Simplified SearchResource to delegate to Store#search instead of duplicating fetch/hydrate logic

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/host/app/services/store.ts Added generic type parameters to search method with overloads for optional metadata, refactored search logic into fetchAndHydrateSearchResults, added _addResourceFromSearchData for efficient resource hydration, and updated imports to support both card and file-meta resources
packages/host/app/resources/search.ts Simplified implementation to delegate to Store#search with includeMeta: true option, removing ~75 lines of duplicated fetch/hydrate logic and unnecessary imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lukemelia lukemelia changed the title Refactor Store#search to support generic types and fix N+1 query issue Refactor Store#search to support FileDef and fix N+1 query issue Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 46m 11s ⏱️ + 1m 44s
1 944 tests ±0  1 927 ✅ +13  17 💤 ±0  0 ❌ ± 0 
1 959 runs  ±0  1 942 ✅ +26  17 💤 ±0  0 ❌  - 13 

Results for commit 992011f. ± Comparison against base commit cf3abb2.

♻️ This comment has been updated with latest results.

@lukemelia lukemelia merged commit 4830d89 into main Feb 5, 2026
100 of 101 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.

1 participant