Batch ContentSummaryLog queries in _consolidate_courses_data#14444
Open
devswithme wants to merge 1 commit intolearningequality:developfrom
Open
Batch ContentSummaryLog queries in _consolidate_courses_data#14444devswithme wants to merge 1 commit intolearningequality:developfrom
devswithme wants to merge 1 commit intolearningequality:developfrom
Conversation
Member
|
Hi @devswithme - could you open an issue for this so we can discuss further before jumping to a solution? I agree with the assessment that there is some potential for optimization here, but I'd rather plan it out a bit more carefully. |
Author
|
Yes can, Thank you @rtibbles. |
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.
Summary
Reduces database queries in the learn plugin at
_consolidate_courses_datafrom 2N to N+1, where N is the number of courses a learner is enrolled in. Previously, for each course node the function issued two separate queries: oneCOUNTfor non-topic descendants and oneCOUNTonContentSummaryLogfor completed content. On a learner's home page or course list with 10 enrolled courses, this produced 20 queries.References
N/A — standalone performance improvement, no related issue.
Reviewer guidance
_consolidate_courses_datainkolibri/plugins/learn/viewsets.py.pytest kolibri/plugins/learn/test/test_learner_course.pyandpytest kolibri/plugins/learn/test/test_learner_classroom.pytoconfirm all existing tests pass.
AI usage
I used Claude to identify the N+1 query pattern and propose the batching approach and reviewed the generated code for correctness specifically verifying UUID type consistency between
ContentNodeandContentSummaryLog, the double-iteration of thecourse_nodesquery set, and the empty-set guard and confirmed the change produces identical output across all existing test cases before accepting it.