summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorSimon Rettberg2020-09-11 14:07:50 +0200
committerSimon Rettberg2020-09-11 14:07:50 +0200
commitb34169e6cb456c0acbeba02e26a8cdfab537f14f (patch)
tree9f500e98dd8978da07e247f2296773a5910efddb /modules-available
parent[locations] Set proper update status when moving openingtime column (diff)
downloadslx-admin-b34169e6cb456c0acbeba02e26a8cdfab537f14f.tar.gz
slx-admin-b34169e6cb456c0acbeba02e26a8cdfab537f14f.tar.xz
slx-admin-b34169e6cb456c0acbeba02e26a8cdfab537f14f.zip
[locationinfo] Always use cached data if backend fails
Previously, we'd only deliver calendar data to the panel if the cache timeout hasn't been reached yet. In case fetching fresh data from the backend fails, go ahead and deliver the old cached data, no matter how old it is.
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php19
1 files changed, 9 insertions, 10 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index fc03671c..6e4d77ac 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -196,13 +196,12 @@ abstract class CourseBackend
$returnValue = [];
$remoteIds = [];
while ($row = $dbquery1->fetch(PDO::FETCH_ASSOC)) {
- //Check if in cache if lastUpdate is null then it is interpreted as 1970
- if ($row['lastcalendarupdate'] + $this->getCacheTime() > $NOW) {
- $returnValue[$row['locationid']] = json_decode($row['calendar']);
- } else {
+ // Check if in cache - if lastUpdate is null then it is interpreted as 1970
+ if ($row['lastcalendarupdate'] + $this->getCacheTime() < $NOW) {
$remoteIds[$row['locationid']] = $row['serverlocationid'];
}
-
+ // Always add to return value - if updating fails, we better use the stale data than nothing
+ $returnValue[$row['locationid']] = json_decode($row['calendar'], true);
}
// No need for additional round trips to backend
if (empty($remoteIds)) {
@@ -234,7 +233,7 @@ abstract class CourseBackend
// if, nothing bad will happen...
Database::exec("UPDATE locationinfo_locationconfig SET lastcalendarupdate = :time
WHERE lastcalendarupdate < :time AND serverid = :serverid AND serverlocationid IN (:slocs)", [
- 'time' => $NOW - $this->getCacheTime() / 2,
+ 'time' => $NOW - ($this->getCacheTime() - 60), // Protect for one minute max.
'serverid' => $this->serverId,
'slocs' => array_values($remoteIds),
]);
@@ -266,15 +265,15 @@ abstract class CourseBackend
'serverid' => $this->serverId,
'serverlocationid' => $serverRoomId,
'ttable' => $value,
- 'now' => $NOW
+ 'now' => $NOW, // Set real "lastupdate" here
));
}
-
- unset($calendar);
}
+ unset($calendar);
// Add rooms that were requested to the final return value
foreach ($remoteIds as $location => $serverRoomId) {
- if (isset($backendResponse[$serverRoomId]) && in_array($location, $requestedLocationIds)) {
+ if (isset($backendResponse[$serverRoomId]) && is_array($backendResponse[$serverRoomId])
+ && in_array($location, $requestedLocationIds)) {
// Only add if we can map it back to our location id AND it was not an unsolicited coalesced refresh
$returnValue[$location] = $backendResponse[$serverRoomId];
}