-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolver: don't use one global instance and implement caching (#10872)
* Addons: pre-fetch the custom `Domain` instance to resolve URLs The `resolver.resolve` method that resolves the URL **always** check for the canonical `Domain` of the canonical `Project`. This means that resolving the URLs for multiple `Version` objects results in querying the exact query over and over again. Instead of repeating this query, we are passing the `Domain` object to `resolver.resolve` method to avoid hiting the DB again since we already known what's the canonical domain for that project, in case it has one. I found this issue while tracking down why there were around ~150 queries to the `projects_domain` table when hitting `/_/addons/` API endpoint on New Relic. * Add tests for number of queries * Add more test cases for Addons API endpoint * Test for custom Domain on flyout versions * Check `use_custom_domain` after knowing the `custom_domain` * Use `functools.lru_cache` for project's domain resolution Caching the project's domain resolution reduces the amount of queries required considerably. It helps to render the addons response among others since it needs to resolve the domain only once no matter how many URLs/versions are needed to be resolved. * Adapt old tests to clean the resolver's cache between each test * Clear cache on tests * Update more tests to match the Resolver cache * Clear cache on footer tests * Use a new instance of `Resolver()` each time it's needed Follows Santos' idea from #10878 (comment) * Minor fix * Revert comment * Typo import * Typo import * Remove unused method
- Loading branch information
Showing
18 changed files
with
344 additions
and
156 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.