Skip to content

Commit 72fa3f8

Browse files
authored
Update wp_bbp_forums.sql
1 parent 3c5be3d commit 72fa3f8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

generate/updates/wp_bbp_forums.sql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ UPDATE wp_bbp_forums o LEFT JOIN (
66
GROUP BY f.forum_id) r ON o.forum_id = r.forum_id
77
SET o.subforum_count = r.subforums;
88

9-
/* Update last_topic_id, basic pass
10-
Maybe add join to posts for the topic status check */
9+
/* Update last_topic_id, basic pass */
1110
UPDATE wp_bbp_forums f LEFT JOIN (
12-
SELECT forum_id, MAX(topic_id) AS topic_id FROM wp_bbp_topics
13-
GROUP BY forum_id) t ON t.forum_id = f.forum_id
11+
SELECT t.forum_id, MAX(t.topic_id) AS topic_id
12+
FROM wp_bbp_topics t
13+
INNER JOIN wp_posts p ON p.ID = t.topic_id AND p.post_status IN ('publish', 'closed')
14+
GROUP BY t.forum_id) t ON t.forum_id = f.forum_id
1415
SET f.last_topic_id = t.topic_id;
1516

16-
/* Update last_reply_id, basic pass
17-
Maybe add join to posts for the reply status check */
17+
/* Update last_reply_id, basic pass */
1818
UPDATE wp_bbp_forums f LEFT JOIN (
19-
SELECT forum_id, MAX(reply_id) AS reply_id FROM wp_bbp_replies
20-
GROUP BY forum_id) r ON r.forum_id = f.forum_id
19+
SELECT t.forum_id, MAX(t.reply_id) AS reply_id
20+
FROM wp_bbp_replies t
21+
INNER JOIN wp_posts p ON p.ID = t.reply_id AND p.post_status IN ('publish')
22+
GROUP BY t.forum_id) r ON r.forum_id = f.forum_id
2123
SET f.last_reply_id = r.reply_id;
2224

2325
/* Update last_topic_id, inner pass, might need to be repeated more than once */

0 commit comments

Comments
 (0)