mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-32931 mod_forum Change forum overview to avoid use of (potentially large and slow ) log table.
This commit is contained in:
parent
6975216336
commit
3b6573536c
1 changed files with 13 additions and 10 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue