Skip to content

OpenConceptLab/ocl_online#782 | The source_version facet counts the versions the requester can view - #1120

Open
paynejd wants to merge 4 commits into
masterfrom
ocl_online-782-version-facet
Open

paynejd wants to merge 4 commits into
masterfrom
ocl_online-782-version-facet

Conversation

@paynejd

@paynejd paynejd commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What the API answers now

The source_version facet of a concept or mapping search counts the matches in the source versions the requester can view, on every route and flag that returns it (facetsOnly, the include-facets and latest-release headers, an owner's, a collection's or an expansion's searches). A name with none is left out. Staff, owners and members see the counts they saw.

How

The index names versions on each concept and mapping, with its source and owner, and no version URL. So:

  • a name of no version the requester can view is dropped;
  • a name that a version they can't view has too is counted again without that version's source, in one more search request, made only then;
  • every other name keeps the index's count.

Outside a collection, a search matches nothing of a source whose HEAD the requester can't view, so such a source's versions add no request, and nothing to the one made for others. In a collection's URL, every version the requester can't view is left out of the count.

count_facet_matches() is the request the collection facets already made, now shared. get_viewable_versions_criteria checks HEAD with one condition for organizations and one for users, so Postgres can join on it. #1119 has the same lines, so either can merge first.

Cost

One database query a faceted search (about 25 ms on production for the 99 commonest names, signed out or signed in). Outside a collection, the extra search request is made only when a counted name is also that of a version the requester can't view in a source they can, such as a private release.

For the reviewer

  • For the minutes the index takes to catch up after a source is made private, its matches can count under a version name that another source shares, as they do under HEAD. A name only that source has is left out at once.
  • The facet stays the top 100 names of the index, so a name can be missing, never wrong, as for the collection facets.
  • Owners or sources whose names differ only in case are one name in the index, so a count can be low, never high.

Tests

New: core/integration_tests/tests_version_facet_access.py.

Refs OpenConceptLab/ocl_online#782, OpenConceptLab/ocl_online#735.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk

paynejd and others added 2 commits December 3, 2026 01:26
…rce_version facet counts the matches in the source versions the requester can view

A source version's name in the facet of a concept or mapping search counts only
the matches in versions the requester can view, on every search that has the
facet, and is left out if there are none.

The rule's HEAD check is one condition per kind of owner, which the database
can join on, as the facet reads the access of every version its names name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
…rsion's source and owner by its URL

As the index names them, which keeps a renamed user's old name too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qUWvM4HRKZktm5NSVk
@paynejd
paynejd requested a review from snyaggarwal December 3, 2026 08:51
@paynejd

paynejd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Reviews: two full Codex passes and a check of the commit after them, a simplification review, and an access-control pass together with #1119. The findings and answers are on OpenConceptLab/ocl_online#782. No P0 or P1 is open.

Lint and the full suite pass on a27f7be (4,280 tests, and 825 with search). No step is needed after the deploy.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes, for one item: the facet recount isn't bounded the way the answer to Codex F2.4 on OpenConceptLab/ocl_online#782 assumes. The rest looks right to me: the dropped and recounted names, the HEAD handling inside and outside a collection's scope, the shared count_facet_matches, and the tests for signed out, outsider, member, owner and staff.

Merge order: after #1119, though either order works. The two PRs carry the same get_viewable_versions_criteria hunk. Both merge cleanly onto today's master (3c2e9c1), together and with #1128.

Blocking: the recount covers every hidden version with a facet's name, not only the private releases of public sources (inline). Codex F2.4 raised the clause limit, and the answer accepted it because "production has 14 private versions of public sources". But get_source_version_names_by_access puts into hidden every source version with that name that the requester can't view. That includes every version of every private source, and the inactive ones. A signed-out or non-member search across all sources has common names among its top 100 (1.0, v1, 1…). So hidden holds every private source in OCL that has a version with such a name, and each one adds a bool branch of three clauses. This has two effects:

  • The extra search request is made on almost every signed-out faceted search, not only when a matched name belongs to a version the requester can't see.
  • The recount's clause count grows with the number of private sources in OCL. Once it passes Elasticsearch's clause limit, the whole facet request answers 400.

Suggested fix: outside a collection's scope, the search only matches content of sources whose HEAD the requester can view. A version of a source with a hidden HEAD can't add to any bucket there, so leave it out of hidden. That leaves the private releases of viewable HEADs, plus the inactive versions, which is about the 14 the F2.4 answer counted. In a collection's scope, keep them all, as test_a_member_s_own_collection_of_another_owner_s_private_source needs. One trade-off: while the index catches up after a source is made private, its matches can still count under a name another source shares. That's the same delay you accepted for the HEAD bucket in F2.1, and it never shows the name itself. If you'd rather keep the code as it is, please show on production how many (owner, source) branches the recount builds for a signed-out /concepts/?q= and /mappings/?q=, against the cluster's clause limit.

Non-blocking: a test with an unrelated private source that has a version with a shared name, such as another org's private source with a 1, would pin this down. It should check the signed-out count and that the recount doesn't list that source.

Comment thread core/common/views.py
).values_list('_viewable', 'version', 'uri'):
if is_viewable:
shown.add(name)
elif uri:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking, see the review summary. This branch adds every source version with the name that the requester can't view, from any owner, private sources and inactive versions included. It isn't limited to private releases of sources they can view. Outside a collection's scope ('collection' not in self.kwargs), the search can't match content of a source whose HEAD is hidden, so those versions only add clauses to the recount. Leaving them out keeps the recount near the 14 private releases the F2.4 answer counted, and it means the extra request is only made when one of those shares a name in the facet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, and it's bounded now, in b53818f: outside a collection, a version of a source whose HEAD the requester can't view no longer counts as hidden. What's left is the versions they can't view in a source they can, and the inactive ones without an active HEAD. In a collection's URL they're all kept, as you suggested.

The signed-out count for production, before and after, is on OpenConceptLab/ocl_online#782.

  • Test: test_private_sources_with_a_version_of_the_same_name. Three private sources, one of them in the same organization as a public one and one a user's, share version names with public sources. Signed out and as another signed-in user, a search of a public source makes one request, though the private ones have its version's name, and the recount made for another public source's private release lists none of them. It fails without the bound.
  • Inactive versions: test_an_inactive_source_s_versions_aren_t_counted keeps them in the recount.
  • While the index catches up after a source is made private: accepted, as for HEAD. For those minutes its matches can count under a name another source shares, and a name only it has is left out at once.
  • Cost: the database query takes about 25 ms on production for the 99 commonest names, up from 5 ms, and it saves the extra search request where only private sources share a name.

Lint is clean, and the full suite passes on a merge with today's master (4,287 tests, and 827 with search). It still merges cleanly with #1119 and #1128.

paynejd and others added 2 commits December 4, 2026 03:02
…ion name again leaves out sources the search can't match

A search outside a collection matches nothing of a source whose HEAD the requester can't view. The source_version facet
no longer lists those sources when it counts a name again, so the request doesn't grow with the number of private
sources, and it isn't made for their sake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVmwkeg26E7AcP35TN
…rsion of the same name is shorter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AaZ4qVmwkeg26E7AcP35TN
@paynejd

paynejd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Reviews of b53818f and b1d0bdf, which answer the review of December 4: one Codex pass and a check of the commit after it, a simplification review, and an access-control pass that compared answers with and without the change. The findings and answers are on OpenConceptLab/ocl_online#782. No P0 or P1 is open.

@snyaggarwal, this is ready for another look.

@paynejd
paynejd requested a review from snyaggarwal December 4, 2026 09:01

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve. b53818f and b1d0bdf fix what I asked for. Outside a collection's scope, the recount now leaves out a version whose source has an active HEAD the requester can't view. So what's left is the private releases of sources they can view, plus the versions of inactive sources. Thanks for the production numbers on OpenConceptLab/ocl_online#782: with every name a viewable version has, the recount drops from 184 branches to 10, and from 16 to 3 for the commonest concept names.

Merge order: after #1119, as in your plan. At b1d0bdf it still merges cleanly onto today's master (3c2e9c1), with #1119 and #1128, and with the new #1132. Lint and Tests pass on b1d0bdf.

What I checked in the delta:

  • The bound. The two ~Exists checks, on organization_id and on user_id, match the HEAD by mnemonic and owner. A NULL owner column matches nothing, so each source is covered by the right check. The check is the same shape as #1119's get_viewable_versions_criteria. It only looks at active HEADs, so a deleted source's versions stay in the recount, as test_an_inactive_source_s_versions_aren_t_counted expects.
  • The extra request on ordinary signed-out searches. Now only names that a private release of a viewable source shares get recounted. test_private_sources_with_a_version_of_the_same_name pins this down: a single request for a search of one public source, and no private source in the recount. It covers another organization's private source, a private source in the same organization, and a user's.
  • Scope. In a collection's scope nothing changes, so test_a_member_s_own_collection_of_another_owner_s_private_source still holds.
  • Staff. For staff, viewable is None and the function returns before the new query.

Non-blocking, and already on the ticket: in a collection's scope the recount still lists every hidden version with a name. You noted that the same bound would be correct there, since that search filters by access too. Production numbers make that fine for now. I agree with leaving F3.1 to #1119's exclude_versions_hidden_by_head.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants