Commit afb0a546 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_discussion: speed up retrieval of discussion posts from a web section

WebSection.getDocumentValueList() returns absolutely all the documents (as catalog brains) reachable by the web section. Then, calling .getUid() on them load all the objects in memory. The number of documents is of the order of hundreds, even on a small ERP5 (web pages, web scripts, etc.).

Limit the documents to retrieve in WebSection_getLatestDiscussionPostList by filtering on the portal_type, and do not load them needlessly in memory.
parent 6e6eb5f0
Pipeline #36099 failed with stage
in 0 seconds
...@@ -2,15 +2,19 @@ ...@@ -2,15 +2,19 @@
Get list of latest Posts which belong to a forum (i.e. websection + predicate) Get list of latest Posts which belong to a forum (i.e. websection + predicate)
""" """
# first get list of all container Threads (details should be set on predicate) # first get list of all container Threads (details should be set on predicate)
parent_uid_list = [x.getUid() for x in context.getDocumentValueList()] parent_uid_list = [
x.uid for x in context.getDocumentValueList(
portal_type="Discussion Thread",
)
]
if not parent_uid_list:
# no parent discussion threads therefore no posts
return []
# get sorted list of all "contained" in them Posts # get sorted list of all "contained" in them Posts
kw['sort_on'] = (('modification_date', 'DESC'),) kw['sort_on'] = (('modification_date', 'DESC'),)
kw['portal_type'] = 'Discussion Post' kw['portal_type'] = 'Discussion Post'
kw['parent_uid'] = parent_uid_list kw['parent_uid'] = parent_uid_list
if len(parent_uid_list)==0:
# no parent discussion threads therefore no posts
return []
return context.portal_catalog(**kw) return context.portal_catalog(**kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment