From ff0edf2d12b91e0e3240df9be502fc9dd88c37e5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 20 Dec 2017 11:31:28 +0800 Subject: [PATCH] MDL-61068 mod_forum: Round timed posts to nearest 60 seconds This slightly reduces the effectiveness of the DB query cache, but gives us correct results every time. --- mod/forum/lib.php | 18 +++++++++--------- mod/forum/rsslib.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 37e94c0b29ab0..2c2135efaca25 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -2025,7 +2025,7 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5 return false; } - $now = round(time(), -2); // db friendly + $now = floor(time() / 60) * 60; // DB Cache Friendly. $fullaccess = array(); $where = array(); @@ -2467,7 +2467,7 @@ function forum_count_discussions($forum, $cm, $course) { static $cache = array(); - $now = round(time(), -2); // db cache friendliness + $now = floor(time() / 60) * 60; // DB Cache Friendly. $params = array($course->id); @@ -2567,7 +2567,7 @@ function forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $ $timelimit = ''; - $now = round(time(), -2); + $now = floor(time() / 60) * 60; $params = array($cm->instance); $modcontext = context_module::instance($cm->id); @@ -2721,7 +2721,7 @@ function forum_get_discussion_neighbours($cm, $discussion, $forum) { } $neighbours = array('prev' => false, 'next' => false); - $now = round(time(), -2); + $now = floor(time() / 60) * 60; $params = array(); $modcontext = context_module::instance($cm->id); @@ -2889,7 +2889,7 @@ function forum_get_default_sort_order($desc = true, $compare = 'd.timemodified', function forum_get_discussions_unread($cm) { global $CFG, $DB, $USER; - $now = round(time(), -2); + $now = floor(time() / 60) * 60; $cutoffdate = $now - ($CFG->forum_oldpostdays*24*60*60); $params = array(); @@ -2961,7 +2961,7 @@ function forum_get_discussions_unread($cm) { function forum_get_discussions_count($cm) { global $CFG, $DB, $USER; - $now = round(time(), -2); + $now = floor(time() / 60) * 60; $params = array($cm->instance); $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm); @@ -6376,7 +6376,7 @@ function forum_tp_is_post_old($post, $time=null) { function forum_tp_get_course_unread_posts($userid, $courseid) { global $CFG, $DB; - $now = round(time(), -2); // DB cache friendliness. + $now = floor(time() / 60) * 60; // DB cache friendliness. $cutoffdate = $now - ($CFG->forum_oldpostdays * 24 * 60 * 60); $params = array($userid, $userid, $courseid, $cutoffdate, $userid); @@ -6475,7 +6475,7 @@ function forum_tp_count_forum_unread_posts($cm, $course, $resetreadcache = false list ($groups_sql, $groups_params) = $DB->get_in_or_equal($mygroups); - $now = round(time(), -2); // db cache friendliness + $now = floor(time() / 60) * 60; // DB Cache friendliness. $cutoffdate = $now - ($CFG->forum_oldpostdays*24*60*60); $params = array($USER->id, $forumid, $cutoffdate); @@ -7635,7 +7635,7 @@ function forum_get_posts_by_user($user, array $courses, $musthaveaccess = false, // Will record forums where the user can freely access everything $forumsearchfullaccess = array(); // DB caching friendly - $now = round(time(), -2); + $now = floor(time() / 60) * 60; // For each course to search we want to find the forums the user has posted in // and providing the current user can access the forum create a search condition // for the forum to get the requested users posts. diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index 6c301b77da4c0..4f413976d93d0 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -146,7 +146,7 @@ function forum_rss_feed_discussions_sql($forum, $cm, $newsince=0) { $modcontext = null; - $now = round(time(), -2); + $now = floor(time() / 60) * 60; // DB Cache Friendly. $params = array(); $modcontext = context_module::instance($cm->id);