perf: check bulk-edit-objects apply_to_all permissions via DB-side exclude/exists

Materialized the full permitted_object_ids() set into a Python set() just
to check membership for the request's objs queryset -- the same pattern
already fixed at four other sites for Document. This one is used by
apply_to_all, where objs can be an unbounded filtered selection (e.g. all
tags matching a filter) rather than a small request-supplied ID list,
making the wasted materialization worse here than at the sites already
fixed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
stumpylog
2026-08-07 13:16:04 -07:00
committed by Trenton H
co-authored by Claude Sonnet 5
parent 3e12425196
commit 48812756fc
+5 -3
View File
@@ -4789,9 +4789,11 @@ class BulkEditObjectsView(PassUserMixin):
if not user.is_superuser:
perm = f"documents.{perm_codename}"
permitted_ids = set(permitted_object_ids(user, object_class, perm_codename))
has_perms = user.has_perm(perm) and all(
obj.pk in permitted_ids for obj in objs
has_perms = (
user.has_perm(perm)
and not objs.exclude(
pk__in=permitted_object_ids(user, object_class, perm_codename),
).exists()
)
if not has_perms: