Some small query optimizations in templatetags#55
Open
jnation3406 wants to merge 1 commit intomasterfrom
Open
Conversation
jnation3406
commented
Jul 21, 2025
| observations = observations.filter(observation_id='template pending') | ||
| cadences = DynamicCadence.objects.filter(active=False, observation_group__in=ObservationGroup.objects.filter(name__in=[o.parameters.get('name', '') for o in observations])) | ||
| observation_groups = {obsgroup for observation in observations for obsgroup in observation.observationgroup_set.all() for cadence in obsgroup.dynamiccadence_set.all() if not cadence.active} |
Author
There was a problem hiding this comment.
Cadences weren't used other than to get their observation_groups so I just changed the code to get those directly and remove the cadences reference. This function still does a bunch of queries but its at least a little less than before.
jnation3406
commented
Jul 21, 2025
| target=target, | ||
| data_type=settings.DATA_PRODUCT_TYPES['photometry'][0], | ||
| value__has_key='filter')).order_by('timestamp') | ||
| value__has_key='filter')).order_by('timestamp').prefetch_related('message') |
Author
There was a problem hiding this comment.
This prefetch greatly reduces the queries since it was doing an extra query per ReducedDatum to get the messages for each before.
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.
Just a few template partial query changes to reduce the number of DB queries needed and speed up performance.