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.
This commit is contained in:
Andrew Nicols 2017-12-20 11:31:28 +08:00
parent 013f0b2266
commit 098f4337d2
2 changed files with 10 additions and 10 deletions

View File

@ -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);
@ -6378,7 +6378,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);
@ -6477,7 +6477,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);
@ -7679,7 +7679,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.

View File

@ -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);