diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 73447527bc..72d7ada3ff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: diff --git a/news/1851.bugfix b/news/1851.bugfix new file mode 100644 index 0000000000..dc29516054 --- /dev/null +++ b/news/1851.bugfix @@ -0,0 +1 @@ +Optimized performance of DexterityObjectPrimaryFieldTarget adapter. @maurits diff --git a/src/plone/restapi/serializer/dxcontent.py b/src/plone/restapi/serializer/dxcontent.py index e497bb6b68..eb0fc44c6e 100644 --- a/src/plone/restapi/serializer/dxcontent.py +++ b/src/plone/restapi/serializer/dxcontent.py @@ -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