Skip to content

N+1 query overhead in get_universes_list #3768

@andersendsa

Description

@andersendsa

Description:

The original code implemented this by iterating over all universes using Python's built-in sorted() function. Inside the key lambda for sorting, it called .get() on the ExerciseUniverses through-model for each item to check if it was marked as default (is_default).
This logic resulted in a classic N+1 query problem. For every list of size N, the system would execute 1 initial query to get all universes, plus N individual database queries to check the is_default flag. f the database grows in the future, this will generate an unnecessary, unscalable load directly proportional to the number of universes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions