diff options
author | Simon Rettberg | 2019-02-20 22:16:55 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-02-20 22:16:55 +0100 |
commit | d96cd82652c6514ec6b45815e33922a503081ef3 (patch) | |
tree | 398dcd763a1b7b82012dae548427e3820844337c /modules-available | |
parent | [locationinfo] Fix minor issues (diff) | |
download | slx-admin-d96cd82652c6514ec6b45815e33922a503081ef3.tar.gz slx-admin-d96cd82652c6514ec6b45815e33922a503081ef3.tar.xz slx-admin-d96cd82652c6514ec6b45815e33922a503081ef3.zip |
[locationinfo] Don't refresh calendars indefinitely
We try to refresh calendars that have recently been used
to coalesce requests, which helps especially with HisInOne.
However, this would in turn make the calendar recently
refreshed so it would keep going on and on, as long as there
is at least one active info panel making actual requests.
Diffstat (limited to 'modules-available')
-rw-r--r-- | modules-available/locationinfo/inc/coursebackend.inc.php | 12 | ||||
-rw-r--r-- | modules-available/locationinfo/install.inc.php | 10 |
2 files changed, 18 insertions, 4 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php index 2eb3f55d..f8389c78 100644 --- a/modules-available/locationinfo/inc/coursebackend.inc.php +++ b/modules-available/locationinfo/inc/coursebackend.inc.php @@ -167,10 +167,11 @@ abstract class CourseBackend } if (empty($requestedLocationIds)) return array(); + $requestedLocationIds = array_values($requestedLocationIds); $NOW = time(); $dbquery1 = Database::simpleQuery("SELECT locationid, calendar, serverlocationid, lastcalendarupdate FROM locationinfo_locationconfig WHERE locationid IN (:locations)", - array('locations' => array_values($requestedLocationIds))); + array('locations' => $requestedLocationIds)); $returnValue = []; $remoteIds = []; while ($row = $dbquery1->fetch(PDO::FETCH_ASSOC)) { @@ -186,17 +187,20 @@ abstract class CourseBackend if (empty($remoteIds)) { return $returnValue; } + // Mark requested locations as used + Database::exec("UPDATE locationinfo_locationconfig SET lastuse = :now WHERE locationid IN (:locations)", + ['locations' => $requestedLocationIds]); // Check if we should refresh other rooms recently requested by front ends $extraLocs = self::TRY_NUM_LOCATIONS - count($remoteIds); if ($this->getRefreshTime() > $this->getCacheTime() && $extraLocs > 0) { $dbquery4 = Database::simpleQuery("SELECT locationid, serverlocationid FROM locationinfo_locationconfig WHERE serverid = :serverid AND serverlocationid NOT IN (:skiplist) - AND lastcalendarupdate BETWEEN :lowerage AND :upperage + AND lastcalendarupdate < :minage AND lastuse > :lastuse LIMIT $extraLocs", array( 'serverid' => $this->serverId, 'skiplist' => array_values($remoteIds), - 'lowerage' => $NOW - $this->getRefreshTime(), - 'upperage' => $NOW - $this->getCacheTime(), + 'lastuse' => $NOW - $this->getRefreshTime(), + 'minage' => $NOW - $this->getCacheTime(), )); while ($row = $dbquery4->fetch(PDO::FETCH_ASSOC)) { $remoteIds[$row['locationid']] = $row['serverlocationid']; diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index bbba3741..3a27d696 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -9,6 +9,7 @@ $t1 = $res[] = tableCreate('locationinfo_locationconfig', ' `openingtime` BLOB, `calendar` BLOB, `lastcalendarupdate` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `lastuse` INT(10) UNSIGNED NOT NULL DEFAULT 0, `lastchange` int(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`locationid`) '); @@ -79,6 +80,15 @@ if ($t3 === UPDATE_NOOP) { // 2017-07-26 Add servername key Database::exec("ALTER TABLE `locationinfo_coursebackend` ADD KEY `servername` (`servername`)"); +// 2019-02-20 Add lastuse column +if (!tableHasColumn('locationinfo_locationconfig', 'lastuse')) { + if (Database::exec("ALTER TABLE locationinfo_locationconfig + ADD `lastuse` INT(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `lastcalendarupdate`") === false) { + finalResponse(UPDATE_FAILED, 'Could not add lastuse column'); + } + $res[] = UPDATE_DONE; +} + // Create response for browser if (in_array(UPDATE_RETRY, $res)) { |