Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce number of queries required for content tagging endpoints #34200

Merged
merged 24 commits into from
Feb 16, 2024

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Feb 7, 2024

Description

Tweak the queries used in the content tagging views to reduce the number of database queries made, and improve response time.

Content tagging is disabled by default, so no one should be affected by this change.

Supporting information

Closes openedx/modular-learning#185

Depends on openedx/openedx-learning#157
Relates to open-craft#633

Internal-ref: FAL-3646

Testing instructions

These changes should be validated by the unit tests.
Please also review the sql queries shown below to ensure that no duplicate queries are being performed, and there's no other obvious ways to reduce these query counts.

List Taxonomies

11 queries for Taxonomy admins (reduced from 16)
E   Captured queries were:
E   1. SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."domain" LIKE 'testserver' ESCAPE '\' LIMIT 21
E   2. SELECT "student_userstanding"."id", "student_userstanding"."user_id", "student_userstanding"."account_status", "student_userstanding"."changed_by_id", "student_userstanding"."standing_last_changed_at" FROM "student_userstanding" WHERE "student_userstanding"."user_id" IS NULL LIMIT 21
E   3. SELECT "theming_sitetheme"."id", "theming_sitetheme"."site_id", "theming_sitetheme"."theme_dir_name" FROM "theming_sitetheme" WHERE "theming_sitetheme"."site_id" = 1 ORDER BY "theming_sitetheme"."id" ASC LIMIT 1
E   4. SAVEPOINT "s140265752491840_x3439"
E   5. SELECT COUNT(*) FROM (SELECT "oel_tagging_taxonomy"."id" AS "col1" FROM "oel_tagging_taxonomy" LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_taxonomy"."id" = "oel_tagging_tag"."taxonomy_id") WHERE ("oel_tagging_taxonomy"."enabled" AND EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 LEFT OUTER JOIN "organizations_organization" U2 ON (U0."org_id" = U2."id") WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U2."short_name" = 'orgA')) LIMIT 1)) GROUP BY 1) subquery
E   6. SELECT "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class", COUNT(DISTINCT "oel_tagging_tag"."id") AS "tags_count" FROM "oel_tagging_taxonomy" LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_taxonomy"."id" = "oel_tagging_tag"."taxonomy_id") WHERE ("oel_tagging_taxonomy"."enabled" AND EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 LEFT OUTER JOIN "organizations_organization" U2 ON (U0."org_id" = U2."id") WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U2."short_name" = 'orgA')) LIMIT 1)) GROUP BY "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class" ORDER BY "oel_tagging_taxonomy"."name" ASC, "oel_tagging_taxonomy"."id" ASC LIMIT 4
E   7. SELECT "content_tagging_taxonomyorg"."id", "content_tagging_taxonomyorg"."taxonomy_id", "content_tagging_taxonomyorg"."org_id", "content_tagging_taxonomyorg"."rel_type" FROM "content_tagging_taxonomyorg" WHERE "content_tagging_taxonomyorg"."taxonomy_id" IN (3, 5, 7, 11)
E   8. SELECT "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "organizations_organization" WHERE "organizations_organization"."id" IN (2, 1)
E   9. SELECT COUNT(*) AS "__count" FROM "oel_tagging_tag" WHERE "oel_tagging_tag"."taxonomy_id" = 3
E   10. RELEASE SAVEPOINT "s140265752491840_x3439"
E   11. SELECT "user_api_userpreference"."id", "user_api_userpreference"."user_id", "user_api_userpreference"."key", "user_api_userpreference"."value" FROM "user_api_userpreference" WHERE ("user_api_userpreference"."key" = 'pref-lang' AND "user_api_userpreference"."user_id" = 2) LIMIT 21
16 queries for content authors (unchanged)
E   Captured queries were:
E   1. SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."domain" LIKE 'testserver' ESCAPE '\' LIMIT 21
E   2. SELECT "student_userstanding"."id", "student_userstanding"."user_id", "student_userstanding"."account_status", "student_userstanding"."changed_by_id", "student_userstanding"."standing_last_changed_at" FROM "student_userstanding" WHERE "student_userstanding"."user_id" IS NULL LIMIT 21
E   3. SELECT "theming_sitetheme"."id", "theming_sitetheme"."site_id", "theming_sitetheme"."theme_dir_name" FROM "theming_sitetheme" WHERE "theming_sitetheme"."site_id" = 1 ORDER BY "theming_sitetheme"."id" ASC LIMIT 1
E   4. SAVEPOINT "s140700559607616_x4616"
E   5. SELECT "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "organizations_organization"
E   6. SELECT "student_courseaccessrole"."id", "student_courseaccessrole"."user_id", "student_courseaccessrole"."org", "student_courseaccessrole"."course_id", "student_courseaccessrole"."role" FROM "student_courseaccessrole" WHERE "student_courseaccessrole"."user_id" = 6
E   7. SELECT "content_libraries_contentlibrary"."id", "content_libraries_contentlibrary"."org_id", "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "content_libraries_contentlibrary" LEFT OUTER JOIN "content_libraries_contentlibrarypermission" ON ("content_libraries_contentlibrary"."id" = "content_libraries_contentlibrarypermission"."library_id") INNER JOIN "organizations_organization" ON ("content_libraries_contentlibrary"."org_id" = "organizations_organization"."id") WHERE ("content_libraries_contentlibrary"."allow_public_read" OR "content_libraries_contentlibrarypermission"."user_id" = 6 OR "content_libraries_contentlibrarypermission"."group_id" IN (SELECT U0."id" FROM "auth_group" U0 INNER JOIN "auth_user_groups" U1 ON (U0."id" = U1."group_id") WHERE U1."user_id" = 6))
E   8. SELECT COUNT(*) FROM (SELECT "oel_tagging_taxonomy"."id" AS "col1" FROM "oel_tagging_taxonomy" LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_taxonomy"."id" = "oel_tagging_tag"."taxonomy_id") WHERE ("oel_tagging_taxonomy"."enabled" AND EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 LEFT OUTER JOIN "organizations_organization" U2 ON (U0."org_id" = U2."id") WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U2."short_name" = 'orgA')) LIMIT 1) AND (EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U0."org_id" IN (1))) LIMIT 1) AND "oel_tagging_taxonomy"."enabled")) GROUP BY 1) subquery
E   9. SELECT "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class", COUNT(DISTINCT "oel_tagging_tag"."id") AS "tags_count" FROM "oel_tagging_taxonomy" LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_taxonomy"."id" = "oel_tagging_tag"."taxonomy_id") WHERE ("oel_tagging_taxonomy"."enabled" AND EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 LEFT OUTER JOIN "organizations_organization" U2 ON (U0."org_id" = U2."id") WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U2."short_name" = 'orgA')) LIMIT 1) AND (EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_taxonomy"."id") AND (U0."org_id" IS NULL OR U0."org_id" IN (1))) LIMIT 1) AND "oel_tagging_taxonomy"."enabled")) GROUP BY "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class" ORDER BY "oel_tagging_taxonomy"."name" ASC, "oel_tagging_taxonomy"."id" ASC LIMIT 4
E   10. SELECT "content_tagging_taxonomyorg"."id", "content_tagging_taxonomyorg"."taxonomy_id", "content_tagging_taxonomyorg"."org_id", "content_tagging_taxonomyorg"."rel_type" FROM "content_tagging_taxonomyorg" WHERE "content_tagging_taxonomyorg"."taxonomy_id" IN (3, 5, 7, 11)
E   11. SELECT "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "organizations_organization" WHERE "organizations_organization"."id" IN (2, 1)
E   12. SELECT COUNT(*) AS "__count" FROM "oel_tagging_tag" WHERE "oel_tagging_tag"."taxonomy_id" = 3
E   13. SELECT "django_content_type"."app_label", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "auth_user_user_permissions" ON ("auth_permission"."id" = "auth_user_user_permissions"."permission_id") INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_user_user_permissions"."user_id" = 6
E   14. SELECT "django_content_type"."app_label", "auth_permission"."codename" FROM "auth_permission" INNER JOIN "auth_group_permissions" ON ("auth_permission"."id" = "auth_group_permissions"."permission_id") INNER JOIN "auth_group" ON ("auth_group_permissions"."group_id" = "auth_group"."id") INNER JOIN "auth_user_groups" ON ("auth_group"."id" = "auth_user_groups"."group_id") INNER JOIN "django_content_type" ON ("auth_permission"."content_type_id" = "django_content_type"."id") WHERE "auth_user_groups"."user_id" = 6
E   15. RELEASE SAVEPOINT "s140700559607616_x4616"
E   16. SELECT "user_api_userpreference"."id", "user_api_userpreference"."user_id", "user_api_userpreference"."key", "user_api_userpreference"."value" FROM "user_api_userpreference" WHERE ("user_api_userpreference"."key" = 'pref-lang' AND "user_api_userpreference"."user_id" = 6) LIMIT 21

Get object tags

Note: Queries shown include changes from open-craft#633.

8 queries for taxonomy admins (increased from 7, added cross-org check)
E   Captured queries were:
E   1. SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."domain" LIKE 'testserver' ESCAPE '\' LIMIT 21
E   2. SELECT "student_userstanding"."id", "student_userstanding"."user_id", "student_userstanding"."account_status", "student_userstanding"."changed_by_id", "student_userstanding"."standing_last_changed_at" FROM "student_userstanding" WHERE "student_userstanding"."user_id" IS NULL LIMIT 21
E   3. SELECT "theming_sitetheme"."id", "theming_sitetheme"."site_id", "theming_sitetheme"."theme_dir_name" FROM "theming_sitetheme" WHERE "theming_sitetheme"."site_id" = 1 ORDER BY "theming_sitetheme"."id" ASC LIMIT 1
E   4. SAVEPOINT "s140265752491840_x1427"
E   5. SELECT "oel_tagging_objecttag"."id", "oel_tagging_objecttag"."object_id", "oel_tagging_objecttag"."taxonomy_id", "oel_tagging_objecttag"."tag_id", "oel_tagging_objecttag"."_name", "oel_tagging_objecttag"."_value", LOWER(COALESCE(T6."value" || '        ', '') || COALESCE(COALESCE(T5."value" || '     ', '') || COALESCE(COALESCE(T4."value" || '        ', '') || COALESCE(COALESCE(COALESCE("oel_tagging_tag"."value", "oel_tagging_objecttag"."_value"), '') || COALESCE('       ', ''), ''), ''), '')) AS "sort_key", COALESCE("oel_tagging_taxonomy"."name", "oel_tagging_objecttag"."_name") AS "taxonomy_name", "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class", "oel_tagging_tag"."id", "oel_tagging_tag"."taxonomy_id", "oel_tagging_tag"."parent_id", "oel_tagging_tag"."value", "oel_tagging_tag"."external_id", T4."id", T4."taxonomy_id", T4."parent_id", T4."value", T4."external_id", T5."id", T5."taxonomy_id", T5."parent_id", T5."value", T5."external_id" FROM "oel_tagging_objecttag" INNER JOIN "oel_tagging_taxonomy" ON ("oel_tagging_objecttag"."taxonomy_id" = "oel_tagging_taxonomy"."id") LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_objecttag"."tag_id" = "oel_tagging_tag"."id") LEFT OUTER JOIN "oel_tagging_tag" T4 ON ("oel_tagging_tag"."parent_id" = T4."id") LEFT OUTER JOIN "oel_tagging_tag" T5 ON (T4."parent_id" = T5."id") LEFT OUTER JOIN "oel_tagging_tag" T6 ON (T5."parent_id" = T6."id") WHERE ("oel_tagging_objecttag"."object_id" = 'course-v1:orgA+101+test' AND NOT (NOT "oel_tagging_taxonomy"."enabled" AND "oel_tagging_taxonomy"."enabled" IS NOT NULL) AND NOT ("oel_tagging_objecttag"."taxonomy_id" IS NULL) AND NOT ("oel_tagging_objecttag"."tag_id" IS NULL AND NOT "oel_tagging_taxonomy"."allow_free_text")) ORDER BY 8 ASC, 7 ASC
E   6. SELECT "content_tagging_taxonomyorg"."id", "content_tagging_taxonomyorg"."taxonomy_id", "content_tagging_taxonomyorg"."org_id", "content_tagging_taxonomyorg"."rel_type" FROM "content_tagging_taxonomyorg" WHERE "content_tagging_taxonomyorg"."taxonomy_id" = 5
E   7. RELEASE SAVEPOINT "s140265752491840_x1427"
E   8. SELECT "user_api_userpreference"."id", "user_api_userpreference"."user_id", "user_api_userpreference"."key", "user_api_userpreference"."value" FROM "user_api_userpreference" WHERE ("user_api_userpreference"."key" = 'pref-lang' AND "user_api_userpreference"."user_id" = 2) LIMIT 21
11 queries for content authors (reduced from 19)
E   Captured queries were:
E   1. SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."domain" LIKE 'testserver' ESCAPE '\' LIMIT 21
E   2. SELECT "student_userstanding"."id", "student_userstanding"."user_id", "student_userstanding"."account_status", "student_userstanding"."changed_by_id", "student_userstanding"."standing_last_changed_at" FROM "student_userstanding" WHERE "student_userstanding"."user_id" IS NULL LIMIT 21
E   3. SELECT "theming_sitetheme"."id", "theming_sitetheme"."site_id", "theming_sitetheme"."theme_dir_name" FROM "theming_sitetheme" WHERE "theming_sitetheme"."site_id" = 1 ORDER BY "theming_sitetheme"."id" ASC LIMIT 1
E   4. SAVEPOINT "s140700559607616_x2209"
E   5. SELECT "student_courseaccessrole"."id", "student_courseaccessrole"."user_id", "student_courseaccessrole"."org", "student_courseaccessrole"."course_id", "student_courseaccessrole"."role" FROM "student_courseaccessrole" WHERE "student_courseaccessrole"."user_id" = 6
E   6. SELECT "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "organizations_organization"
E   7. SELECT "content_libraries_contentlibrary"."id", "content_libraries_contentlibrary"."org_id", "organizations_organization"."id", "organizations_organization"."created", "organizations_organization"."modified", "organizations_organization"."name", "organizations_organization"."short_name", "organizations_organization"."description", "organizations_organization"."logo", "organizations_organization"."active" FROM "content_libraries_contentlibrary" LEFT OUTER JOIN "content_libraries_contentlibrarypermission" ON ("content_libraries_contentlibrary"."id" = "content_libraries_contentlibrarypermission"."library_id") INNER JOIN "organizations_organization" ON ("content_libraries_contentlibrary"."org_id" = "organizations_organization"."id") WHERE ("content_libraries_contentlibrary"."allow_public_read" OR "content_libraries_contentlibrarypermission"."user_id" = 6 OR "content_libraries_contentlibrarypermission"."group_id" IN (SELECT U0."id" FROM "auth_group" U0 INNER JOIN "auth_user_groups" U1 ON (U0."id" = U1."group_id") WHERE U1."user_id" = 6))
E   8. SELECT "oel_tagging_objecttag"."id", "oel_tagging_objecttag"."object_id", "oel_tagging_objecttag"."taxonomy_id", "oel_tagging_objecttag"."tag_id", "oel_tagging_objecttag"."_name", "oel_tagging_objecttag"."_value", LOWER(COALESCE(T6."value" || '        ', '') || COALESCE(COALESCE(T5."value" || '     ', '') || COALESCE(COALESCE(T4."value" || '        ', '') || COALESCE(COALESCE(COALESCE("oel_tagging_tag"."value", "oel_tagging_objecttag"."_value"), '') || COALESCE('       ', ''), ''), ''), '')) AS "sort_key", COALESCE("oel_tagging_taxonomy"."name", "oel_tagging_objecttag"."_name") AS "taxonomy_name", "oel_tagging_taxonomy"."id", "oel_tagging_taxonomy"."name", "oel_tagging_taxonomy"."description", "oel_tagging_taxonomy"."enabled", "oel_tagging_taxonomy"."allow_multiple", "oel_tagging_taxonomy"."allow_free_text", "oel_tagging_taxonomy"."visible_to_authors", "oel_tagging_taxonomy"."export_id", "oel_tagging_taxonomy"."_taxonomy_class", "oel_tagging_tag"."id", "oel_tagging_tag"."taxonomy_id", "oel_tagging_tag"."parent_id", "oel_tagging_tag"."value", "oel_tagging_tag"."external_id", T4."id", T4."taxonomy_id", T4."parent_id", T4."value", T4."external_id", T5."id", T5."taxonomy_id", T5."parent_id", T5."value", T5."external_id" FROM "oel_tagging_objecttag" INNER JOIN "oel_tagging_taxonomy" ON ("oel_tagging_objecttag"."taxonomy_id" = "oel_tagging_taxonomy"."id") LEFT OUTER JOIN "oel_tagging_tag" ON ("oel_tagging_objecttag"."tag_id" = "oel_tagging_tag"."id") LEFT OUTER JOIN "oel_tagging_tag" T4 ON ("oel_tagging_tag"."parent_id" = T4."id") LEFT OUTER JOIN "oel_tagging_tag" T5 ON (T4."parent_id" = T5."id") LEFT OUTER JOIN "oel_tagging_tag" T6 ON (T5."parent_id" = T6."id") WHERE ("oel_tagging_objecttag"."object_id" = 'course-v1:orgA+101+test' AND NOT (NOT "oel_tagging_taxonomy"."enabled" AND "oel_tagging_taxonomy"."enabled" IS NOT NULL) AND NOT ("oel_tagging_objecttag"."taxonomy_id" IS NULL) AND NOT ("oel_tagging_objecttag"."tag_id" IS NULL AND NOT "oel_tagging_taxonomy"."allow_free_text") AND "oel_tagging_taxonomy"."enabled" AND EXISTS(SELECT 1 AS "a" FROM "content_tagging_taxonomyorg" U0 WHERE (U0."rel_type" = 'OWN' AND U0."taxonomy_id" = ("oel_tagging_objecttag"."taxonomy_id") AND (U0."org_id" IS NULL OR U0."org_id" IN (1))) LIMIT 1)) ORDER BY 8 ASC, 7 ASC
E   9. SELECT "content_tagging_taxonomyorg"."id", "content_tagging_taxonomyorg"."taxonomy_id", "content_tagging_taxonomyorg"."org_id", "content_tagging_taxonomyorg"."rel_type" FROM "content_tagging_taxonomyorg" WHERE "content_tagging_taxonomyorg"."taxonomy_id" = 5
E   10. RELEASE SAVEPOINT "s140700559607616_x2209"
E   11. SELECT "user_api_userpreference"."id", "user_api_userpreference"."user_id", "user_api_userpreference"."key", "user_api_userpreference"."value" FROM "user_api_userpreference" WHERE ("user_api_userpreference"."key" = 'pref-lang' AND "user_api_userpreference"."user_id" = 6) LIMIT 21

Deadline

None

Was requesting org=$orgA instead of org=orgA, and so wasn't testing the
queries we needed to test.
@openedx-webhooks
Copy link

openedx-webhooks commented Feb 7, 2024

Thanks for the pull request, @pomegranited! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Feb 7, 2024
which reduces the query count.

TO DO: once PR is merged and tagged, update the requirement here.
to avoid re-querying.

Changes TaxonomyOrg.get_organizations to return the "all orgs" flag too,
which makes it useful in the rules.
instead of prefetching all the tags.
because SELECT COUNT at the database level is more efficient than
returning a bunch of data we don't need.
instead of querying for CourseAccessRoles

Also
* removes the can_change_objecttag override method -- we only need to
  override the can_change_objecttag_taxonomy / _object+id methods to
  achieve our rules changes.
* fixes up some misleading comments, and underscores some internal
  rules method names.
Avoids fetching and re-fetching Organizations by caching the full
Organization list for the duration of the request.
Avoids re-fetching the libraries that a user has been granted access to
by caching the data we need from these libraries for the duration of the
request.
@pomegranited pomegranited force-pushed the jill/tagging-less-queries branch 2 times, most recently from a7047c9 to 85eb4f1 Compare February 14, 2024 05:57
Copy link
Contributor

@yusuf-musleh yusuf-musleh left a comment

Choose a reason for hiding this comment

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

👍 This is some really great work @pomegranited ! I followed the commits while reviewing as you suggested. I just had a few minor nits and a question.

  • I tested this: Checked that the updated tests with less query counts pass
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

* fix: prevent cross-org ObjectTags from being created

A "cross-org" ObjectTag is when the object_id references an org that is not in the taxonomy's allowed list of orgs.

Similarly, we forbid creating object tags for a taxonomy with no allowed orgs listed.

class TaggingRulesCache:
"""
Caches data required for computing rules for the duration of the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

This may not have been necessary if we'd have used bridgekeeper instead of rules for defining the permissions. My bad for that original mistake. It's a nice solution for now though :)

@bradenmacdonald
Copy link
Contributor

@pomegranited I went to merge this, but there's a conflict. Please fix it and I'll merge on Tuesday.

@rpenido
Copy link
Contributor

rpenido commented Feb 16, 2024

@pomegranited I went to merge this, but there's a conflict. Please fix it and I'll merge on Tuesday.

Hi @bradenmacdonald! I fixed the merge conflict in case you still check it today or Monday.

@bradenmacdonald bradenmacdonald merged commit b6366b6 into openedx:master Feb 16, 2024
46 checks passed
@bradenmacdonald bradenmacdonald deleted the jill/tagging-less-queries branch February 16, 2024 20:15
@openedx-webhooks
Copy link

@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Tagging] Reduce the number of queries used in content tagging REST API
6 participants