Permalink
Browse files

MDL-41191 mod_forum: avoid DISTINCT on TEXT columns

It is not supported by all db engines
  • Loading branch information...
danpoltawski authored and damyon committed Aug 21, 2013
1 parent 94bcd74 commit 5db91ce2a43f81adef94e385800523a8df814bf2
Showing with 11 additions and 10 deletions.
  1. +11 −10 mod/forum/lib.php
View
@@ -8149,16 +8149,18 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
// table and join to the userid there. If we are looking for posts then we need
// to join to the forum_posts table.
if (!$discussionsonly) {
$joinsql = 'JOIN {forum_discussions} fd ON fd.course = c.id
JOIN {forum_posts} fp ON fp.discussion = fd.id';
$wheresql = 'fp.userid = :userid';
$params = array('userid' => $user->id);
$subquery = "(SELECT DISTINCT fd.course
FROM {forum_discussions} fd
JOIN {forum_posts} fp ON fp.discussion = fd.id
WHERE fp.userid = :userid )";
} else {
$joinsql = 'JOIN {forum_discussions} fd ON fd.course = c.id';
$wheresql = 'fd.userid = :userid';
$params = array('userid' => $user->id);
$subquery= "(SELECT DISTINCT fd.course
FROM {forum_discussions} fd
WHERE fd.userid = :userid )";
}
$params = array('userid' => $user->id);
// Join to the context table so that we can preload contexts if required.
if ($includecontexts) {
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
@@ -8169,11 +8171,10 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
// Now we need to get all of the courses to search.
// All courses where the user has posted within a forum will be returned.
$sql = "SELECT DISTINCT c.* $ctxselect
$sql = "SELECT c.* $ctxselect
FROM {course} c
$joinsql
$ctxjoin
WHERE $wheresql";
WHERE c.id IN ($subquery)";
$courses = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
if ($includecontexts) {
array_map('context_instance_preload', $courses);

0 comments on commit 5db91ce

Please sign in to comment.