[BE] Skip foreign-key existence queries in CompetencyCriterion.save()
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Start with CompetencyCriterion.save() in src/openedx_learning/applets/cbe/models/criteria.py and check the existing _validate_rule_source() exclusion in api.py. Add or update tests for foreign-key reads during bulk_update_competency_criteria() with override values and a named profile, while confirming override payload validation still runs. Done means each changed criterion adds two queries and missing references are still rejected by the database.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
User Story
As a course author bulk-editing competency criteria, I want the update to skip redundant database reads for each criterion, in order to keep large batches fast.
Description
CompetencyCriterion.save() calls full_clean() with no exclude. As a result, Django runs a separate SELECT on every save to check that each foreign key's row still exists. We need to exclude the foreign keys from that call and let the database's foreign-key constraints enforce them.
Context
- Follow-up from the review of #874 (for #759): https://github.com/openedx/openedx-core/pull/874#discussion_r4297349913
- Measured on #874: each changed criterion costs 4 queries with override values and 5 with a named profile. Of those, 2 (3 with a profile) are
full_clean()looking up the foreign-key rows.
Acceptance Criteria
Scenario: Saving a criterion doesn't re-read the rows it points at
Given an existing criterion
When its rule is changed and it is saved
Then the save writes the criterion and its history record
And it does not read the criterion's group, tag association, or rule profile
Scenario: Bulk update cost no longer includes the foreign-key reads
Given a batch of criteria in one group whose rule the update changes
When the bulk update applies override values, and again when it names a rule profile
Then each changed criterion adds 2 queries to the batch, in both cases
Scenario: Override payload validation still runs on save
Given a criterion
When it is saved with override values whose payload doesn't fit the rule type
Then the save is refused with a validation error, as before
Scenario: A reference to a missing row is still refused
Given a criterion that points at a group, tag association, or rule profile that doesn't exist
When it is saved
Then the database refuses the write
Technical Details
This is a suggested approach, not the source of truth. The User Story, Description, and Acceptance Criteria define what must be true when the work is done.
Approach
- In
CompetencyCriterion.save()insrc/openedx_learning/applets/cbe/models/criteria.py, passexclude=["group", "object_tag", "rule_profile"]tofull_clean()._validate_rule_source()inapi.pyalready uses the same exclude.clean()still runs, so override payload validation is unchanged. - Excluding a field also skips its not-null check. A dangling or missing foreign key now fails as an
IntegrityErrorfrom the database instead of aValidationErrorfromsave(). The API paths look up the group and tag before they build a criterion, so they shouldn't notice. Confirm that no caller catches theValidationErrorfor this case. - On SQLite and PostgreSQL, Django creates foreign-key constraints as
DEFERRABLE INITIALLY DEFERRED, so the database checks a dangling reference at commit, not atsave(). A test for the last scenario needs to force the check, for example withconnection.check_constraints(). MySQL checks immediately. - Pin the per-criterion cost with a
django_assert_num_queriestest onbulk_update_competency_criteria(): a fixed number of queries, plus 2 per changed criterion, for both override values and a named profile.
Additional context
CompetencyRuleProfile.save()in the same file also callsfull_clean()with noexclude(organization,course,competency_taxonomy). Profiles aren't saved in bulk, so it's out of scope here.- Django's
ForeignKey.validate(), which runs the lookup: https://github.com/django/django/blob/stable/5.2.x/django/db/models/fields/related.py
- Ngôn ngữ chính
- Python
- Star
- 10
- Fork
- 33
- Merge trung bình
- 2 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openedx/openedx-core
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
openedx/openedx-core#831 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
openedx/openedx-core#827 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
discovery
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
openedx/openedx-core#908 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Follow-up BE] Hide archived tagging records in edx-platform's content_tagging appCó thể đã có người làm @tbain đã nhận 2 ngày trước. Đang mở
openedx/openedx-core#903 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Follow-up - BE] Block dominance conflicts on taxonomy re-importCó thể đã có người làm @alezconsultant đã nhận 1 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
openedx/openedx-core#902 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openedx/openedx-core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nansencenter/geodataset#39 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
awslabs/visual-asset-management-system#804 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[18.0] werkzeug: AttributeErrorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
odoo/odoo#297927 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
link-rot
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100