Ticket #1071 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Discussion Forum lists reports 0 topics if there are 0 replies.

Reported by: anonymous Assigned to: Blackhex
Priority: normal Component: DiscussionPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.10

Description

The query used for the Forum List view does a simple join of tf and mf. Hence, if there are no messages for a forum topic, the forum topic count is 0.

I think the right fix is to replace the following query with a LEFT JOIN as follows.

I tested by taking the query from the DEBUG log (before) and changing the simple join on tf,mf to a LEFT JOIN (after). I used sqlite3 interface to confirm desired results

before:

SELECT f.id, f.name, f.author, f.time, f.moderators, f.forum_group, f.subject, f.description, tm.topics, tm.replies, tm.lastreply, tm.lasttopic FROM forum f LEFT JOIN ( SELECT tf.forum AS forum, topics, lasttopic, replies, lastreply FROM (SELECT COUNT(id) AS topics, MAX(time) AS lasttopic, forum FROM topic GROUP BY forum) tf, (SELECT COUNT(id) AS replies, MAX(time) AS lastreply, forum FROM message GROUP BY forum) mf WHERE tf.forum = mf.forum) tm ON f.id = tm.forum ORDER BY f.id ASC;

after:

SELECT f.id, f.name, f.author, f.time, f.moderators, f.forum_group, f.subject, f.description, tm.topics, tm.replies, tm.lastreply, tm.lasttopic FROM forum f LEFT JOIN ( SELECT tf.forum AS forum, topics, lasttopic, replies, lastreply FROM (SELECT COUNT(id) AS topics, MAX(time) AS lasttopic, forum FROM topic GROUP BY forum) tf LEFT JOIN (SELECT COUNT(id) AS replies, MAX(time) AS lastreply, forum FROM message GROUP BY forum) mf ON tf.forum = mf.forum) tm ON f.id = tm.forum ORDER BY f.id ASC;

Attachments

Change History

02/03/07 22:44:07 changed by acro

I don't know anything about queries but I can confirm the problem:
Forum lists reports 0 topics if there are 0 replies.
When you post a reply it starts working correctly.

Thank you for the plugin.

02/04/07 03:47:14 changed by Blackhex

  • status changed from new to assigned.

OK. I've fixed this little error already but I'm waiting for some more changes before commiting them.

02/08/07 17:45:51 changed by Blackhex

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in changeset 1941.


Add/Change #1071 (Discussion Forum lists reports 0 topics if there are 0 replies.)




Change Properties
Action