Skip to content

[Enhancement]: Batch ContentSummaryLog queries in _consolidate_courses_data #14453

Description

@devswithme

This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: develop, release-0.19.3

Current behavior

2N db query in the learn plugin at kolibri/plugins/learn/viewsets.py > _consolidate_courses_data.

Desired behavior

Reduces database queries in the learn plugin at _consolidate_courses_data from 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: one COUNT for non-topic descendants and one COUNT on ContentSummaryLog for completed content. On a learner's home page or course list with 10 enrolled courses, this produced 20 queries. (current open PR: #14444)

Value add

Add efficiency in database query on the learner's home or course list page.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions