perf: eager-load store and product type on store apps admin list#200
Open
dan2k3k4 wants to merge 1 commit into
Open
perf: eager-load store and product type on store apps admin list#200dan2k3k4 wants to merge 1 commit into
dan2k3k4 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Eager-loads the store and product-type relations on the Store Apps admin list to remove an N+1 query.
Greptile Summary
This PR adds a single line to
getEloquentQuery()onPolydockStoreAppResourcethat eager-loads thestoreandproductTypeBelongsTo relations. Both relations are used as Filament table columns (store.name,productType.name), so without eager-loading they were being resolved one-by-one for every row on the admin list.store(),productType()) are correctly defined on thePolydockStoreAppmodel and match the string keys passed to->with().getEloquentQuery()chain alongside thewithCount()already in place.Confidence Score: 5/5
Safe to merge — a one-line additive change to an existing query builder chain with no side effects.
Both eager-loaded relation names (
store,productType) exactly match the methods defined on the model, and both are actively consumed as table columns in the Filament list. The change is additive and isolated to the admin list query; no other behavior is affected.No files require special attention.
Important Files Changed
->with(['store', 'productType'])togetEloquentQuery()to eager-load both BelongsTo relations that are referenced as table columns (store.name,productType.name), eliminating the N+1 query on the admin list page.Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Browser participant FilamentList as Filament Admin List participant DB as Database Note over FilamentList,DB: Before this PR (N+1) Browser->>FilamentList: Load Store Apps page FilamentList->>DB: "SELECT * FROM polydock_store_apps (+ counts)" loop For each row FilamentList->>DB: "SELECT * FROM polydock_stores WHERE id = ?" FilamentList->>DB: "SELECT * FROM polydock_product_types WHERE id = ?" end DB-->>Browser: Response Note over FilamentList,DB: After this PR (eager-load) Browser->>FilamentList: Load Store Apps page FilamentList->>DB: "SELECT * FROM polydock_store_apps (+ counts)" FilamentList->>DB: "SELECT * FROM polydock_stores WHERE id IN (...)" FilamentList->>DB: "SELECT * FROM polydock_product_types WHERE id IN (...)" DB-->>Browser: Response%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Browser participant FilamentList as Filament Admin List participant DB as Database Note over FilamentList,DB: Before this PR (N+1) Browser->>FilamentList: Load Store Apps page FilamentList->>DB: "SELECT * FROM polydock_store_apps (+ counts)" loop For each row FilamentList->>DB: "SELECT * FROM polydock_stores WHERE id = ?" FilamentList->>DB: "SELECT * FROM polydock_product_types WHERE id = ?" end DB-->>Browser: Response Note over FilamentList,DB: After this PR (eager-load) Browser->>FilamentList: Load Store Apps page FilamentList->>DB: "SELECT * FROM polydock_store_apps (+ counts)" FilamentList->>DB: "SELECT * FROM polydock_stores WHERE id IN (...)" FilamentList->>DB: "SELECT * FROM polydock_product_types WHERE id IN (...)" DB-->>Browser: ResponseReviews (1): Last reviewed commit: "perf: eager-load store and product type ..." | Re-trigger Greptile