Repository navigation
perf: cache the country lookup and index files.subject_uuid - #291
Merged
Merged
Conversation
getCountryCodeByCurrency() and getCountryCodeByName() rebuilt the full countries dataset (a 4.7 MB JSON file plus flag hydration) on every call. Storefront serializes a country per store, so listing stores paid that cost once per record and network store lists could take minutes. The name/ISO2/currency rows are now built once, kept in the application cache and memoized per process. Cache failures fall back to building the lookup, and flushCountryLookup() resets it.
Store media, product images and proofs of delivery are looked up by subject_uuid, which had no index, so each lookup scanned the whole files table.
5 of 7 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #291 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 7931 7940 +9
===========================================
Files 438 438
Lines 25665 25670 +5
===========================================
+ Hits 25665 25670 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Store listings in Storefront could take minutes because each store's resource calls
Utils::getCountryCodeByCurrency(). Every call built a newPragmaRX\Countriesinstance, decoded the 4.7 MB countries dataset, hydrated flags, and mapped about 250 countries. So the cost was paid once per store, on every request.getCountryCodeByName()had the same pattern.Changes
Utils::getCountryLookup()builds the name / ISO2 / currency rows once, stores them in the application cache (fleetbase:utils:country-lookup:v1), and memoizes them per process.Utils::flushCountryLookup()resets the memo and, optionally, the cached copy.getCountryCodeByCurrency()andgetCountryCodeByName()use the cached lookup. Their behaviour is unchanged, including returning the first matching country (for example,USDstill resolves to the first match in the dataset).files.subject_uuid. Store media, product images and proofs of delivery are loaded by subject and previously scanned the wholefilestable.Companion change: fleetbase/storefront
fix/network-stores-performance(per-store queries in the store resource and network store listing).Validation
pest tests/Unit/Support/UtilsTest.php: new tests cover a cache hit, memoization, rebuild after flush, flushing the memo only, and an unavailable cache store.utils reads composer package keyword metadata from the lock file; it fails only because the run was from a checkout outside the monorepo layout, and passes from the normalpackages/core-apicheckout.php-cs-fixer --dry-runon the changed files: clean.collect()/Countries::all()typing).Risk
:v1), so a future shape change can bump it.