Skip to content

Conversation

@jnation3406
Copy link

Just a few template partial query changes to reduce the number of DB queries needed and speed up performance.

@jnation3406 jnation3406 requested review from cmccully and jrfarah July 21, 2025 20:52
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}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prefetch greatly reduces the queries since it was doing an extra query per ReducedDatum to get the messages for each before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants