We apologize for untranslated text, you can use the Google Translation button to get an automatic translation of the web page in the language of your choice.

DBForumPlugin: Displaying the latest conversations for all forums

Anonymous 2018-11-29 · on 2/13/14 at 3:55 PM

Hello,

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
</jalios:foreach>

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,

16 pts
Kevin Bransard - on 2/13/14 at 5:07 PM
Best answer

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

#1

Hello,

Thank you very much for your reply! Yes, we are using DBForum 5.0 (on JCMS 7.1.3). The "Portlet Last DBForum topic" was what I was looking for in first place, in order not to reinvent the wheel with a JSP.

We'll probably use the builtin portlet. If we need to customise it further, we can always use the template source code as "inspiration". I see it's using the DBForumManager class to retrieve the latest conversations in a paged view, instead of performing a query via HibernateUtil.

Anonymous 2018-11-29 · on 2/14/14 at 9:33 AM
#2

Yes it uses a PublicationCriteria to perform the query, which is our abstraction of the Hibernate Criteria.

You can use it like this :

    PageResult pr = new PageResult<AbstractDBForumTopic>();
    
    PublicationCriteria pubCriteria = new PublicationCriteria(AbstractDBForumTopic.class);
    pubCriteria
    .setFirstResult(0)
    .setMaxResults(10)
    .setOrder("mdate")
    .setAscendingOrder(true)
    .setMember(loggedMember);

    if(ws != null){
      pubCriteria.setCustomCriterion(Restrictions.eq(WORKSPACE_ID_FIELD, workspace.getId()));
    }
    
    pr =  HibernateUtil.queryPublication(pubCriteria);
    return pr;

Which returns a PageResult

Kevin Bransard · on 2/14/14 at 10:30 AM
10 pts
Olivier Jaquemet · on 2/13/14 at 4:28 PM

Hello David,

When perfoming query on DBData, do not use the jalios:query and the dataset parameter.

For your use case (displaying first 40 dbforum), use 

List<DBForum> dbforumList = HibernateUtil.getDBDataList(DBForum.class, 0, 40);



#1

Hello Olivier,

Thank you for your reply, the response time has certainly improved! Actually, I would need to retrieve the latest DBForumPost elements. How can I do that?

Anonymous 2018-11-29 · on 2/13/14 at 4:41 PM
#2

Check the javadoc of HibernateUtil, there are other methods which accept sort order.

Olivier Jaquemet · on 2/13/14 at 4:45 PM
1 pt