Repository navigation
OpenConceptLab/ocl_online#452 | An expansion keeps the rules it was built under until it's rebuilt - #1136
Open
paynejd wants to merge 7 commits into
Open
OpenConceptLab/ocl_online#452 | An expansion keeps the rules it was built under until it's rebuilt#1136paynejd wants to merge 7 commits into
paynejd wants to merge 7 commits into
Conversation
…uilt under until it's rebuilt Under FHIR's rules, the first edit that met two versions of one source rebuilt the whole HEAD, so members nobody touched could change or go. Now an edit of an expansion built before the rules does what it does without them, and an edit of one built under them changes only what the references it adds or removes select. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…rameters, and can run again if it fails Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…rsion, and saves what its re-add selects Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…ps versions apart takes seconds, not minutes Past about 130,000 memberships a NOT IN over them no longer fits in PostgreSQL's work_mem, and reads them all again for each one: 232 s for an add to an expansion with 200,000, and 2 s now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…from one read of them A join was as fast only where PostgreSQL has statistics, which a new expansion's memberships don't have yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
… memory, not in each reference's queries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
…s the database for them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed
paynejd
marked this pull request as ready for review
December 5, 2026 00:53
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge after #1094, and before
EXPANSION_FHIR_RULES_TOGGLE(#1110) is turned on anywhere. With that switch off, members, saved results and recorded versions stay as they are.What it means for people
A collection keeps the rules it was built with until it's rebuilt. New collections and new releases are built under the rules the switch gives.
Two limits:
The problem
With the switch on, #1090 keeps two versions of one source apart in an expansion. Every HEAD that exists was built without that. The first edit that met two versions of a source rebuilt the whole HEAD, so members nobody touched could change or go. Every removal evaluated all the references that were left, with the same effect. So did the first edit after the switch was turned off again.
An edit of a very large HEAD was also slow. Three queries compared all its recorded memberships with each other, which takes PostgreSQL minutes above about 130,000 of them (at the default
work_mem). Two whole releases of a source with 66,000 concepts are enough for that.How it works
Expansion.versions_apartnow says which rules an expansion was built under. There is no migration.What isn't obvious
1.0.x, a filter, a code that ignores case. Only keeping versions apart follows the HEAD. So in an old HEAD, a new reference to1.0.xselects what that release holds, and an edit can record the release that such a reference resolves to.Where to read
core/collections/member_versions.py: the last three points of the docstring, thendecide,is_wholeandrecord_members, the methods fromleaves_foundtowanted_ids, anddedupe.core/collections/models.py:Expansion.delete_referencesandreadd_selected, then the changes inadd_references.core/common/tasks.pyandcore/tasks/models.py: the removal's task takes a third argument. One that has it no longer clears the record of an earlier one that failed, which may have been of other concepts.Tests
core/collections/tests/tests_edits.pyis new, with 39 tests. Three of them make random edits of random expansions with fixed seeds, while the sources change:Outside the suite I ran each on 250 more expansions: 1,665 edits and 250 removals, with no difference.
Eleven tests of #1090 and #1094 change, because an edit no longer rebuilds, and a build now reads the switch once:
test_a_reference_added_to_an_expansion_built_without_the_rules, now…_built_with_one_versiontest_built_without_the_rules_then_added_to_under_themtest_a_rebuild_for_new_rules_keeps_its_version_locks, nowtest_an_edit_once_they_are_off_again_rebuilds_nothingtest_a_rebuild_for_the_rules_drops_the_locks_no_reference_usedtest_a_concept_version_s_lock_goes_when_other_references_took_anothertest_a_rebuild_for_the_rules_drops_the_value_set_locks_no_reference_usedtest_a_rebuild_for_new_rules_reads_only_the_references_it_was_giventest_one_version_a_source_never_asks_the_toggle, now…_asks_the_toggle_oncetest_the_toggle_is_read_only_for_a_wildcard_or_a_declared_algorithm, nowtest_a_build_reads_the_toggle_oncetest_version_parameters_read_the_toggle_once_a_build_at_most, nowtest_with_version_parameters_tootest_code_references_ask_for_the_rules_only_for_a_code_with_no_exact_match, now…_ask_for_the_rules_onceTime on a HEAD of 40,000 codes with one reference each, on my machine:
On a HEAD with two whole releases of 100,000 codes (200,000 memberships):
Two are slower. A removal from a HEAD of 40,000 codes with one reference each, built before the rules, takes 53 s, as it does today with the switch off (23 s before this change, with it on). Removing one of two whole releases of 40,000 codes takes 9.9 s, where it took 7.5 s.
The full suite passes (4,818 tests, and 822 with Elasticsearch), coverage is 97%, and lint is clean. It also passes on the branches above this one with this merged in, and no test of theirs changes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qVQviVc1p6MQwqUUed