kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Filtering by "contains quiz" is very slow

Open rtibbles opened this issue 9 months ago • 0 comments

Observed behavior

Currently filtering by "contains quiz" is a very slow operation, due to the incredibly inefficient query that is used to refine the search

Expected behavior

Filtering by contains quiz should be performant!

As this involves doing a descendants lookup of a contains query in a textfield of JSON, it is unlikely that we will be able to make this query performant by itself, so this will probably require pre-annotation in order to handle this.

Solution

The solution is to use the new modality field that will be added to ContentNode.

Replace all inefficient options__contains='"modality": "QUIZ"' queries with direct field lookups: modality=modalities.QUIZ

The indexed modality field will provide O(log n) lookup performance instead of scanning JSON fields.

Implementation locations

Code that currently uses inefficient queries:

  • kolibri/core/content/api.py:288 - options__contains='"modality": "QUIZ"'
  • kolibri/core/content/api.py:571 - options__contains='"modality": "QUIZ"'
  • kolibri/plugins/coach/kolibri_plugin.py:51 - options__contains='"modality": "QUIZ"'

These should be updated to use:

from le_utils.constants import modalities

# Replace options__contains queries with:
modality=modalities.QUIZ

Steps to reproduce

With the Kolibri QA channel loaded on your Kolibri device go to create a quiz and choose the second option from the drop down menu to create it from a practice quiz.

Observe that navigating the topic tree like this is rather slow.

Context

  • Kolibri version: 0.18.0

🤖 This issue was updated with resolution details by Claude Code, under supervision, review and final edits by @rtibbles 🤖

rtibbles avatar Mar 27 '25 20:03 rtibbles