-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Make primary field target adapter return early. #1851
Conversation
@mauritsvanrees thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
When there is no primary field, do not go through all fields. First compare the field name, then the permission: comparing two strings is cheaper. If the field name matches, stop iterating over other fields: you have already found the field.
865a6a8
to
4e928a9
Compare
@jenkins-plone-org please run jobs |
@@ -220,23 +220,24 @@ def __init__(self, context, request): | |||
|
|||
def __call__(self): | |||
primary_field_name = self.get_primary_field_name() | |||
if not primary_field_name: | |||
return | |||
for schema in iterSchemata(self.context): | |||
read_permissions = mergedTaggedValueDict(schema, READ_PERMISSIONS_KEY) | |||
|
|||
for name, field in getFields(schema).items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would:
field = getFields(schema).get(primary_field_name)
work, rather than looping on all the schema fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not want to change too much, but testing it seems to work, so yes, let's go for this. Change made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks okay as is. The suggestion from @ale-rt also makes sense. @mauritsvanrees I'll let you decide whether to adjust it.
…ating over all fields.
I now have a totally unrelated error only on Plone 6.0 Python 3.12:
The same run last week was fine. Difference: last week this used Ubuntu 22.04. Now it uses 24.04. In the upcoming Plone 6.0.14 I am upgrading Pillow to 11.0.0. That could magically solve it. :-/ |
This was ubuntu-latest until last week. With ubuntu-24.04 on Python 3.12 Pillow is not installed correctly. See #1851 (comment)
@jenkins-plone-org please run jobs |
Branch: refs/heads/main Date: 2024-12-16T20:56:01-08:00 Author: Maurits van Rees (mauritsvanrees) <[email protected]> Commit: plone/plone.restapi@93ceb88 Make primary field target adapter return early. (#1851) * Make primary field target adapter return early. When there is no primary field, do not go through all fields. First compare the field name, then the permission: comparing two strings is cheaper. If the field name matches, stop iterating over other fields: you have already found the field. * Update news/1851.bugfix * Primary field target: get primary_field_name directly instead of iterating over all fields. * Run tests on ubuntu-22.04. This was ubuntu-latest until last week. With ubuntu-24.04 on Python 3.12 Pillow is not installed correctly. See plone/plone.restapi#1851 (comment) * Update src/plone/restapi/serializer/dxcontent.py --------- Co-authored-by: David Glick <[email protected]> Files changed: A news/1851.bugfix M .github/workflows/tests.yml M src/plone/restapi/serializer/dxcontent.py
Branch: refs/heads/main Date: 2024-12-16T20:56:01-08:00 Author: Maurits van Rees (mauritsvanrees) <[email protected]> Commit: plone/plone.restapi@93ceb88 Make primary field target adapter return early. (#1851) * Make primary field target adapter return early. When there is no primary field, do not go through all fields. First compare the field name, then the permission: comparing two strings is cheaper. If the field name matches, stop iterating over other fields: you have already found the field. * Update news/1851.bugfix * Primary field target: get primary_field_name directly instead of iterating over all fields. * Run tests on ubuntu-22.04. This was ubuntu-latest until last week. With ubuntu-24.04 on Python 3.12 Pillow is not installed correctly. See plone/plone.restapi#1851 (comment) * Update src/plone/restapi/serializer/dxcontent.py --------- Co-authored-by: David Glick <[email protected]> Files changed: A news/1851.bugfix M .github/workflows/tests.yml M src/plone/restapi/serializer/dxcontent.py
📚 Documentation preview 📚: https://plonerestapi--1851.org.readthedocs.build/