Bug 1492768 - Optimize alert summary queries executed from graphs view#4050
Merged
wlach merged 1 commit intomozilla:masterfrom Sep 20, 2018
Merged
Bug 1492768 - Optimize alert summary queries executed from graphs view#4050wlach merged 1 commit intomozilla:masterfrom
wlach merged 1 commit intomozilla:masterfrom
Conversation
Not a complete solution but hopefully this will improve things enough to stop the timeouts we're seeing.
a9e2a2c to
18d22e8
Compare
wlach
commented
Sep 20, 2018
| class PerformanceSignatureSerializer(serializers.ModelSerializer): | ||
| framework_id = serializers.SlugRelatedField( | ||
| slug_field="id", source="framework", | ||
| queryset=PerformanceFramework.objects.all()) |
Contributor
Author
There was a problem hiding this comment.
This resulted in a query which was expensive and unnecessary, since we have the framework id already.
wlach
commented
Sep 20, 2018
| repository__active_status='active').select_related( | ||
| 'repository').prefetch_related( | ||
| 'alerts', | ||
| 'alerts__classifier', |
Contributor
Author
There was a problem hiding this comment.
We can prefetch the classifier to save a bunch of queries when we serialize.
wlach
commented
Sep 20, 2018
| 'alerts__series_signature__option_collection__option') | ||
| queryset = PerformanceAlertSummary.objects.filter( | ||
| repository__active_status='active').select_related( | ||
| 'repository').prefetch_related( |
Contributor
Author
There was a problem hiding this comment.
Since repository is a foreign key on the alert summary table, it makes more sense to put the fetch in a selected_related clause. More or less cleanup.
Contributor
Author
|
This seems to improve query times by a factor of 2 on stage. There's still a ridiculous number of queries, but that's a little harder to fix (we may want to consider either using a custom endpoint which looks up alert summaries based on alerts or using graphql here) |
edmorley
approved these changes
Sep 20, 2018
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.
Not a complete solution but hopefully this will improve things enough
to stop the timeouts we're seeing.