-
Notifications
You must be signed in to change notification settings - Fork 58
Only preload interactive algorithms for reader studies with budget #4741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1307,9 +1307,17 @@ def delete_stale_provisioned_concurrency_configs(self): | |
| @acks_late_micro_short_task | ||
| @transaction.atomic | ||
| def preload_interactive_algorithms(): | ||
| from grandchallenge.reader_studies.models import Question | ||
| from grandchallenge.reader_studies.models import Question, ReaderStudy | ||
| from grandchallenge.workstations.models import Session | ||
|
|
||
| reader_studies_out_of_budget = [ | ||
| rs.pk | ||
| for rs in ReaderStudy.objects.exclude(max_credits__isnull=True).only( | ||
| "pk", "max_credits" | ||
| ) | ||
| if not rs.has_budget | ||
| ] | ||
|
|
||
| active_interactive_algorithms = ( | ||
| Question.objects.filter( | ||
| reader_study__workstation_sessions__status__in=[ | ||
|
|
@@ -1318,6 +1326,7 @@ def preload_interactive_algorithms(): | |
| Session.RUNNING, | ||
| ], | ||
| ) | ||
| .exclude(reader_study__pk__in=reader_studies_out_of_budget) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to use the negative here? Filtering is going to be more efficient than excluding.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This seemed easier to read to me and I didn't know that filtering is more efficient than excluding. I'll change it to filter(). |
||
| .exclude(interactive_algorithm="") | ||
| .values_list("interactive_algorithm", flat=True) | ||
| .distinct() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query has an N+1 problem (due to expensive queries in
credits_consumed). It's an asynchronous task, but still. Currently looking at annotatingcredits_consumedin the DB to make this more efficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Struggling with turning
credits_consumedinto an annotation. It involves nested aggregates, and gets quite complex. Maybe prefetching the related objects is good enough here? In general, I would like to know how bad the performance is before I continue trying to optimize this.@jmsmkn could you compare timings for the following 2 queries:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Those timings seem fine to me for an asynchronous task and not worth the added complexity of moving the consumed credits into a DB annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would still be worth including the prefetching if those objects are going to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very true, I had that as a local commit, but forgot to push!