Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-32931 mod_forum Change forum overview to avoid use of (potentiall…

…y large and slow ) log table.
  • Loading branch information...
commit 3b6573536c38c6176329c118069b1a5d1760f80e 1 parent 6975216
Tom Lanyon authored dmonllao committed
Showing with 13 additions and 10 deletions.
  1. +13 −10 mod/forum/lib.php
23 mod/forum/lib.php
View
@@ -1311,21 +1311,24 @@ function forum_print_overview($courses,&$htmlarray) {
}
- // get all forum logs in ONE query (much better!)
+ // look for new posts since lastaccess
+ $course_tuples = join(
+ ' OR ',
+ array_fill(0, count($visited_courses), '(f.course = ? AND p.created > ?)')
+ );
+
+ $sql = "SELECT f.id, COUNT(*) "
+ .'FROM {forum_posts} p, {forum_discussions} d, {forum} f '
+ .'WHERE p.discussion = d.id AND d.forum = f.id '
+ ."AND ($course_tuples) "
+ ."AND p.userid != ? "
+ ."GROUP BY f.id";
+
$params = array();
- $sql = "SELECT instance,cmid,l.course,COUNT(l.id) as count FROM {log} l "
- ." JOIN {course_modules} cm ON cm.id = cmid "
- ." WHERE (";
foreach ($courses as $course) {
- $sql .= '(l.course = ? AND l.time > ?) OR ';
$params[] = $course->id;
$params[] = $course->lastaccess;
}
- $sql = substr($sql,0,-3); // take off the last OR
-
- $sql .= ") AND l.module = 'forum' AND action = 'add post' "
- ." AND userid != ? GROUP BY cmid,l.course,instance";
-
$params[] = $USER->id;
if (!$new = $DB->get_records_sql($sql, $params)) {
Please sign in to comment.
Something went wrong with that request. Please try again.