MDL-56139 core: changes after peer review

- No longer use the Fibonacci sequence for delaying the timeout.
  It is too aggressive.
- The backoff_timer AMD module now expects the callback AND the
  backoff function to be passed to the constructor.
- Added ability to specify polling frequency in config.php.
- Added helper function to return the cache key.
- Reworded the parameters for clarity.
This commit is contained in:
Mark Nelson
2016-11-16 10:22:52 +08:00
parent fb1469d84f
commit ffd7798c96
19 changed files with 192 additions and 159 deletions
+8 -10
View File
@@ -291,31 +291,29 @@ class api {
* @param int $limitfrom
* @param int $limitnum
* @param string $sort
* @param int $createdfrom the timestamp from which the messages were created
* @param int $createdto the time up until which the message was created
* @param int $timefrom the time from the message being sent
* @param int $timeto the time up until the message being sent
* @return array
*/
public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0,
$sort = 'timecreated ASC', $createdfrom = 0, $createdto = 0) {
$sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
if (!empty($createdfrom)) {
if (!empty($timefrom)) {
// Check the cache to see if we even need to do a DB query.
$cache = \cache::make('core', 'message_last_created');
$ids = [$otheruserid, $userid];
sort($ids);
$key = implode('_', $ids);
$cache = \cache::make('core', 'message_time_last_message_between_users');
$key = helper::get_last_message_time_created_cache_key($otheruserid, $userid);
$lastcreated = $cache->get($key);
// The last known message time is earlier than the one being requested so we can
// just return an empty result set rather than having to query the DB.
if ($lastcreated && $lastcreated < $createdfrom) {
if ($lastcreated && $lastcreated < $timefrom) {
return [];
}
}
$arrmessages = array();
if ($messages = helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum,
$sort, $createdfrom, $createdto)) {
$sort, $timefrom, $timeto)) {
$arrmessages = helper::create_messages($userid, $messages);
}