Skip to content

Avoid full store list materialization in core fallback paths#729

Draft
KrzysztofPajak with Copilot wants to merge 3 commits into
developfrom
copilot/fix-fetch-all-stores-performance
Draft

Avoid full store list materialization in core fallback paths#729
KrzysztofPajak with Copilot wants to merge 3 commits into
developfrom
copilot/fix-fetch-all-stores-performance

Conversation

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

IStoreService.GetAllStores() was being used in multiple hot fallback paths that only needed a single store, causing full store collection loading into memory. This change introduces targeted store lookups and rewires key call sites to remove unnecessary full-list fetches.

  • Service API changes

    • Added GetFirstStore() to IStoreService for single-store fallback retrieval.
    • Added dedicated cache keys:
      • Grand.stores.first
      • Grand.stores.host-{host}
  • StoreService query/caching optimization

    • Implemented GetFirstStore() as an ordered single-record query.
    • Reworked GetStoreByHost(host) to query by host directly (with per-host cache), instead of loading all stores then filtering in memory.
    • Updated delete safety check to use existence semantics (Skip(1).Any()) rather than loading all stores.
  • High-impact call-site rewiring

    • Replaced GetAllStores().FirstOrDefault() fallbacks with GetFirstStore() in:
      • store context initialization
      • work context initialization
      • campaign message store resolution
      • message provider fallback store resolution
  • Example (pattern change)

    // before
    var store = await _storeService.GetStoreById(storeId) ??
                (await _storeService.GetAllStores()).FirstOrDefault();
    
    // after
    var store = await _storeService.GetStoreById(storeId) ??
                await _storeService.GetFirstStore();

Copilot AI and others added 2 commits July 5, 2026 16:30
Co-authored-by: KrzysztofPajak <16772986+KrzysztofPajak@users.noreply.github.com>
Co-authored-by: KrzysztofPajak <16772986+KrzysztofPajak@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix performance issue of fetching all stores to memory Avoid full store list materialization in core fallback paths Jul 5, 2026
Copilot AI requested a review from KrzysztofPajak July 5, 2026 16:32
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.

All stores are fetched from DB to memory

2 participants