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

Add endpoint that uses plone.volto block_types indexer (wip) #1789

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonaspiterek
Copy link
Member

ToDo

  • Add page title data to response

@mister-roboto
Copy link

@jonaspiterek thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

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!

Copy link

netlify bot commented May 17, 2024

Deploy Preview for plone-restapi ready!

Name Link
🔨 Latest commit 2cbeef5
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/6647708f0eee3b00082b8e39
😎 Deploy Preview https://deploy-preview-1789--plone-restapi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +16 to +17
for blocktype in blocktypes:
brains = catalog.searchResults(block_types=blocktype)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure this can be optimized to one query with removal of the for loop.

result[blocktype] = Counter()

for brain in brains:
obj = brain.getObject()
Copy link
Sponsor Member

@jensens jensens May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above query could ask the object_provides index for the (marker) interface of the volto.blocks behavior. This would save several an object wake ups.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried the object_provides index for the marker interface of the volto.blocks behavior like so: brains = catalog(object_provides=IBlocks.__identifier__) which returns brains just like the block_types index. And so I am asking my self: Doesn't this make the block_types index completely unnecessary? Because from the brains I get the object and from there I get the block values.

/cc @davisagli

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonaspiterek You can do that but then you end up loading the full object for all the content items that have blocks, and loading the full object is slower than loading the metadata that is stored as part of the catalog. The block_types index exists for the use case where you want to find all the items that have a particular type of block, without actually loading the full objects.

Also the block_types index properly finds blocks that are nested inside other blocks, which your code doesn't do yet.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonaspiterek Btw if you just want to find out how many items have each type of block, you can also get that efficiently from the index like this (if I recall correctly): api.portal.get_tool("portal_catalog").Indexes["block_types"].uniqueValues(withLengths=1)

Copy link
Sponsor Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonaspiterek Is there a compelling reason to add a new service for this? It should be possible to query the block_types index using the existing @querystring-search service (we might need to add a criterion for it in the querystring registry settings)

@jonaspiterek
Copy link
Member Author

@davisagli no there is no particular reason for this to be an extra service. I can take a look on how to do that via the @querystring-search service if an extra service for the indexer is not wanted.

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

Successfully merging this pull request may close these issues.

None yet

4 participants