Skip to content

Commit

Permalink
Merge pull request #1797 from UlrichB22/perf_get_acls
Browse files Browse the repository at this point in the history
_get_acls: use meta data if available to avoid index query
  • Loading branch information
RogerHaase authored Nov 12, 2024
2 parents 20c44ac + 5eae35e commit 2d4884d
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/moin/storage/middleware/protecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,34 @@ def _get_acls(self, itemid=None, fqname=None):
q = fqname.query
else:
raise ValueError("need itemid or fqname")
item = self.get_item(**q)
acl = item.acl
fqname = item.fqname
if acl is not None:
return [acl]
acl_cfg = self._get_configured_acls(fqname)
if acl_cfg["hierarchic"]:

meta_available = False
if self.meta:
"""use meta data if available to avoid index query"""
meta_keys = [*self.meta.keys()]
if (
itemid
and fqname
and FQNAMES in meta_keys
and ITEMID in meta_keys
and itemid == self.meta[ITEMID]
and fqname == self.meta[FQNAMES][0]
):
meta_available = True
if ACL in meta_keys:
acl = self.meta[ACL]
return [acl]

item = None
if not meta_available or self._get_configured_acls(fqname)["hierarchic"]:
"""self.meta is not valid or namespace uses hierarchic acls and we need item parentids"""
item = self.get_item(**q)
acl = item.acl
fqname = item.fqname
if acl is not None:
return [acl]

if self._get_configured_acls(fqname)["hierarchic"]:
# check parent(s), recursively
parentids = item.parentids
if parentids:
Expand Down

0 comments on commit 2d4884d

Please sign in to comment.