Skip to content

Commit

Permalink
[fc] Repository: plone.restapi
Browse files Browse the repository at this point in the history
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 &lt;[email protected]&gt;

Files changed:
A news/1851.bugfix
M .github/workflows/tests.yml
M src/plone/restapi/serializer/dxcontent.py
  • Loading branch information
davisagli committed Dec 17, 2024
1 parent 0357cc8 commit 5fbdfdc
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
Repository: plone.api
Repository: plone.restapi


Branch: refs/heads/main
Date: 2024-12-16T20:18:31-08:00
Author: David Glick (davisagli) <[email protected]>
Commit: https://github.com/plone/plone.api/commit/4dfc6039cfc2cbf7c2f735d7da67c3ce99d8cace
Date: 2024-12-16T20:56:01-08:00
Author: Maurits van Rees (mauritsvanrees) <[email protected]>
Commit: https://github.com/plone/plone.restapi/commit/93ceb885d78b804d4cc0fe8ef636c5bee1b3c20d

fix lint
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 https://github.com/plone/plone.restapi/pull/1851#issuecomment-2547097591

* Update src/plone/restapi/serializer/dxcontent.py

---------

Co-authored-by: David Glick &lt;[email protected]&gt;

Files changed:
M MANIFEST.in
A news/1851.bugfix
M .github/workflows/tests.yml
M src/plone/restapi/serializer/dxcontent.py

b'diff --git a/MANIFEST.in b/MANIFEST.in\nindex b9ca1361..162a5ec9 100644\n--- a/MANIFEST.in\n+++ b/MANIFEST.in\n@@ -13,6 +13,7 @@ global-exclude *.pyc\n include pyproject.toml\n recursive-exclude news *\n exclude news\n+recursive-exclude .vscode *\n \n # added by check-manifest\n recursive-include src *.py\n'
b"diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml\nindex 73447527bc..72d7ada3ff 100644\n--- a/.github/workflows/tests.yml\n+++ b/.github/workflows/tests.yml\n@@ -3,7 +3,7 @@ on: [push, pull_request]\n jobs:\n build:\n if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name\n- runs-on: ubuntu-latest\n+ runs-on: ubuntu-22.04\n strategy:\n fail-fast: false\n matrix:\ndiff --git a/news/1851.bugfix b/news/1851.bugfix\nnew file mode 100644\nindex 0000000000..dc29516054\n--- /dev/null\n+++ b/news/1851.bugfix\n@@ -0,0 +1 @@\n+Optimized performance of DexterityObjectPrimaryFieldTarget adapter. @maurits\ndiff --git a/src/plone/restapi/serializer/dxcontent.py b/src/plone/restapi/serializer/dxcontent.py\nindex e497bb6b68..eb0fc44c6e 100644\n--- a/src/plone/restapi/serializer/dxcontent.py\n+++ b/src/plone/restapi/serializer/dxcontent.py\n@@ -220,23 +220,26 @@ def __init__(self, context, request):\n \n def __call__(self):\n primary_field_name = self.get_primary_field_name()\n+ if not primary_field_name:\n+ return\n for schema in iterSchemata(self.context):\n read_permissions = mergedTaggedValueDict(schema, READ_PERMISSIONS_KEY)\n \n- for name, field in getFields(schema).items():\n- if not self.check_permission(read_permissions.get(name), self.context):\n- continue\n-\n- if name != primary_field_name:\n- continue\n-\n- target_adapter = queryMultiAdapter(\n- (field, self.context, self.request), IPrimaryFieldTarget\n- )\n- if target_adapter:\n- target = target_adapter()\n- if target:\n- return target\n+ field = getFields(schema).get(primary_field_name)\n+ if field is None:\n+ continue\n+ if not self.check_permission(\n+ read_permissions.get(primary_field_name),\n+ self.context,\n+ ):\n+ return\n+\n+ target_adapter = queryMultiAdapter(\n+ (field, self.context, self.request), IPrimaryFieldTarget\n+ )\n+ if not target_adapter:\n+ return\n+ return target_adapter()\n \n def get_primary_field_name(self):\n fieldname = None\n"

0 comments on commit 5fbdfdc

Please sign in to comment.