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 numberOfFolderishDocuments to catalog metadata #118

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions news/numberOfFolderishDocuments.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add numberOfFolderishDocuments catalog metadata to allow UX affordance in folder contents in Volto.
[jaroel]
4 changes: 4 additions & 0 deletions src/plone/volto/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
zcml:condition="not-have plone-60"
/>

<adapter
factory=".indexers.numberOfFolderishDocuments"
name="numberOfFolderishDocuments"
/>
<adapter
factory=".indexers.hasPreviewImage"
name="hasPreviewImage"
Expand Down
9 changes: 9 additions & 0 deletions src/plone/volto/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
from plone.dexterity.interfaces import IDexterityContent
from plone.indexer.decorator import indexer
from plone.volto.behaviors.preview import IPreview
from plone.volto.interfaces import IFolderishDocument


@indexer(IFolderishDocument)
def numberOfFolderishDocuments(obj):
Copy link
Member

@wesleybl wesleybl May 16, 2023

Choose a reason for hiding this comment

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

@jaroel I think this metadata will not be updated if we add a content in the container. Indexing would have to be called in the event of adding content. I saw a discussion about this at: https://community.plone.org/t/indexing-how-to-index-contained-items/17428

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'm adding an indexer, not an event listener. This works just fine (tm).
Thanks for having a look though!

Copy link
Member

Choose a reason for hiding this comment

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

@jaroel surprisingly for me it works! I saw that when we add content to a container, it is reindexed. Even its modification date is changed.

@mauritsvanrees @jensens @davisagli , was that thought or is it an "accident"? Indexing is one of the most expensive things in Plone. If this has not been thought of, it would be good to remove this behavior.

Copy link
Member

Choose a reason for hiding this comment

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

@wesleybl I don't think that is intentional. Unfortunately changing it could be disruptive since existing implementations are probably relying on it happening. So I would say we can change it in Plone 7 (but maybe there is a way to make it available in an opt-in fashion in Plone 6)

Copy link
Member

Choose a reason for hiding this comment

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

I think it may be intentional. Think only of caching: if content is added to a container, but this does not mark the container as changed, then you will keep getting the previous version, and not see the new content.

Then again, the new content itself get indexed and causes the catalogCounter to be increased, which is usually checked in eTags by plone.app.caching. So it may not be needed for that.

Copy link
Member

Choose a reason for hiding this comment

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

@mauritsvanrees I generally don't cache with eTag. But I think it has a modified date eTag. So it might make sense to change the container modification date when content is added. Perhaps what could be improved is reindexing only the modification date, instead of reindexing all indexes.

"""
For UX affordance to show which pages aren't leaf nodes.
"""
return len(obj.objectIds(spec=obj.meta_type, ordered=False))


@indexer(IPreview)
Expand Down
1 change: 1 addition & 0 deletions src/plone/volto/profiles/default/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<column value="head_title" />
<column value="hasPreviewImage" />
<column value="image_field" />
<column value="numberOfFolderishDocuments" />
</object>
2 changes: 1 addition & 1 deletion src/plone/volto/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1016</version>
<version>1017</version>
<dependencies>
<dependency>profile-plone.restapi:blocks</dependency>
</dependencies>
Expand Down