Skip to content

Conversation

@bjester
Copy link
Member

@bjester bjester commented Dec 3, 2024

Summary

The following query-- which originates from the publish modal providing a list of content languages, or from testing the existence of a language in a channel-- was taking too long:

SELECT DISTINCT "contentcuration_contentnode"."language_id",
                "contentcuration_contentnode"."tree_id",
                "contentcuration_contentnode"."lft"
FROM "contentcuration_contentnode"
WHERE (
    "contentcuration_contentnode"."language_id" IS NOT NULL
    AND CAST("contentcuration_contentnode"."node_id" AS uuid) IN (
        SELECT U0."id"
        FROM "kolibri_public_contentnode" U0
        WHERE U0."channel_id" = '<CHANNEL_ID>')
            AND NOT ("contentcuration_contentnode"."id" IN ('<MAIN_TREE_ID>'))
)
ORDER BY
    "contentcuration_contentnode"."tree_id" ASC,
    "contentcuration_contentnode"."lft" ASC
;

The following issues were addressed with the query:

  • Removed querying against the public nodes since those are only populated after publishing and for public library channels
  • Removed the default ordering added by MPTT
  • Updated the query to directly query against the content nodes using the tree_id then filter from there

The updates should now produce a SQL query similar to:

WITH t AS (
  SELECT id, language_id
  FROM contentcuration_contentnode
  WHERE tree_id = '<TREE_ID>'
)
SELECT DISTINCT t.language_id
FROM t
WHERE t.language_id IS NOT NULL
  AND t.id != '<MAIN_TREE_ID>'

References

#4666
https://learningequality.slack.com/archives/C0LK8QS9J/p1733174857751199

Reviewer guidance

  • Tests were implemented for the original feature, which were ran before and after, and passed each time

Copy link
Member

@akolson akolson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me and query is now more direct. Thanks @bjester for the optimization.

@bjester bjester merged commit b3c96fe into learningequality:hotfixes Dec 3, 2024
13 checks passed
@bjester bjester deleted the inherit-modal branch December 3, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants