Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] restful: what is the reason of just returning the result of super() #33

Open
AungKoKoLin1997 opened this issue Feb 10, 2024 · 0 comments

Comments

@AungKoKoLin1997
Copy link

AungKoKoLin1997 commented Feb 10, 2024

return ids
if self.env.is_system():
# rules do not apply for the superuser
return len(ids) if count else ids
if not ids:
return 0 if count else []
# Work with a set, as list.remove() is prohibitive for large lists of documents
# (takes 20+ seconds on a db with 100k docs during search_count()!)
orig_ids = ids
ids = set(ids)
# For attachments, the permissions of the document they are attached to
# apply, so we must remove attachments for which the user cannot access
# the linked document.
# Use pure SQL rather than read() as it is about 50% faster for large dbs (100k+ docs),
# and the permissions are checked in super() and below anyway.
model_attachments = defaultdict(lambda: defaultdict(set)) # {res_model: {res_id: set(ids)}}
binary_fields_attachments = set()
self._cr.execute(
"""SELECT id, res_model, res_id, public, res_field FROM ir_attachment WHERE id IN %s""", [tuple(ids)]
)
for row in self._cr.dictfetchall():
if not row["res_model"] or row["public"]:
continue
# model_attachments = {res_model: {res_id: set(ids)}}
model_attachments[row["res_model"]][row["res_id"]].add(row["id"])
# Should not retrieve binary fields attachments
if row["res_field"]:
binary_fields_attachments.add(row["id"])
if binary_fields_attachments:
ids.difference_update(binary_fields_attachments)
# To avoid multiple queries for each attachment found, checks are
# performed in batch as much as possible.
for res_model, targets in model_attachments.items():
if res_model not in self.env:
continue
if not self.env[res_model].check_access_rights("read", False):
# remove all corresponding attachment ids
ids.difference_update(itertools.chain(*targets.values()))
continue
# filter ids according to what access rules permit
target_ids = list(targets)
allowed = self.env[res_model].with_context(active_test=False).search([("id", "in", target_ids)])
for res_id in set(target_ids).difference(allowed.ids):
ids.difference_update(targets[res_id])
# sort result according to the original sort ordering
result = [id for id in orig_ids if id in ids]
# If the original search reached the limit, it is important the
# filtered record set does so too. When a JS view recieve a
# record set whose length is bellow the limit, it thinks it
# reached the last page.
if len(orig_ids) == limit and len(result) < len(orig_ids):
result.extend(
self._search(
args,
offset=offset + len(orig_ids),
limit=limit,
order=order,
count=count,
access_rights_uid=access_rights_uid,
)[: limit - len(result)]
)
return len(result) if count else list(result)

I found you added some customize code but you added return statement before your customization. The code after return statement will never be reached and worked. So, is that intentional or any reason?

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

No branches or pull requests

1 participant