DBForumPlugin: Displaying the latest conversations for all forums
We are creating a portlet to display the latest conversations for all the forums of type DBForum in our site. Given that it's not feasible to use a standard PortletQueryForeach, I am creating a JSP "from scratch". The current version of the JSP has the following structure:
// This query takes a lot to execute
<jalios:query name="resultSet" dataset="<%= channel.getDataSet(DBForumPost.class) %>" comparator="<%= Publication.getMdateComparator() %>"/>
// Boilerplate code removed for readability
// Display loop
<jalios:foreach collection="<%= resultSet %>" name="forumPost" type="DBForumPost" max="40" >
// Get the parent topic and forum for each post
// If the post has not been displayed, display it in a table row in the following way:
// Topic name | Number of posts | Date of last post | Author of last post
With the method above, the call to <jalios:query> takes a lot to execute (around 2,5 seconds, according to some basic profile using System.nanoTime()). In comparison, the <jalios:foreach> loop takes only around 100ms. Restricting the query (for instance, getting only the posts from the latest year), only made things worse (3,5 seconds).
Is there any better way to get the "latest conversations" for all the forums? (I know it's implemented for a single forum in the "Full Display" template). If not, how can we improve the efficiency of the call to <jalios:query>?
Thanks in advance,
Hello, which version of the DBForum are you using ?
There's a portlet in the plugin called "Portlet Last DBForum topic" which lists the DBForum topic, ordered by their modification date. There's also two tabs which filter these topics by "Followed topic" or by "My topics" in this portlet.
This portlet has been introduced in DBForum 4.0.
Concerning the query, it is better to use HibernateUtil to perform your query, and to filter this query through sql criterias.
As an example, to return the last topic of a given forum, you would perform the following query :
List list = HibernateUtil.query(AbstractDBForumTopic.class, "forumId",yourforumId,"mdate desc");
You can also limit the number of element returned by setting the first and the max results. Check this page for further informations : http://community.jalios.com/docs/javadoc/com/jalios/jcms/db/HibernateUtil.html