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

Make primary field target adapter return early. #1851

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: [push, pull_request]
jobs:
build:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand Down
1 change: 1 addition & 0 deletions news/1851.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimized performance of DexterityObjectPrimaryFieldTarget adapter. @maurits
31 changes: 17 additions & 14 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,26 @@ 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():
if not self.check_permission(read_permissions.get(name), self.context):
continue

if name != primary_field_name:
continue

target_adapter = queryMultiAdapter(
(field, self.context, self.request), IPrimaryFieldTarget
)
if target_adapter:
target = target_adapter()
if target:
return target
field = getFields(schema).get(primary_field_name)
if field is None:
continue
if not self.check_permission(
read_permissions.get(primary_field_name),
self.context,
):
return

target_adapter = queryMultiAdapter(
(field, self.context, self.request), IPrimaryFieldTarget
)
if not target_adapter:
return
return target_adapter()

def get_primary_field_name(self):
fieldname = None
Expand Down
Loading