Implemented incremental fetch

This commit is contained in:
tuffnerdstuff 2021-03-30 00:01:28 +02:00
parent b95f517ada
commit 08a5050b7c
3 changed files with 38 additions and 6 deletions

View file

@ -20,6 +20,8 @@ if (!$share->exists()) {
} else {
header("Content-Type: text/json");
$sinceTime=$_GET["since"] ?? null;
// Solo and group shares have different internal structures. Figure out the
// correct type so that it can be output.
switch ($share->getType()) {
@ -34,7 +36,7 @@ if (!$share->exists()) {
"expire" => $share->getExpirationTime(),
"serverTime" => microtime(true),
"interval" => $session->getInterval(),
"points" => $session->getPoints(),
"points" => $session->getPoints($sinceTime),
"encrypted" => $session->isEncrypted(),
"salt" => $session->getEncryptionSalt()
));
@ -46,7 +48,7 @@ if (!$share->exists()) {
"expire" => $share->getExpirationTime(),
"serverTime" => microtime(true),
"interval" => $share->getAutoInterval(),
"points" => $share->getAllPoints()
"points" => $share->getAllPoints($sinceTime)
));
break;
}

View file

@ -565,12 +565,12 @@ class GroupShare extends Share {
}
// Returns a map of nicknames and the users' corresponding coordinates.
public function getAllPoints() {
public function getAllPoints($sinceTime) {
$points = array();
$hosts = $this->getHosts();
foreach ($hosts as $nick => $host) {
if ($host->exists()) {
$points[$nick] = $host->getPoints();
$points[$nick] = $host->getPoints($sinceTime);
}
}
return $points;
@ -758,8 +758,22 @@ class Client {
}
// Returns a list of all point arrays for this session.
public function getPoints() {
public function getPoints($sinceTime) {
if (is_null($sinceTime)) {
// return all memcached points
return $this->sessionData["points"];
} else {
$newPoints = [];
// FIXME: use map instead of indices
$timeIndex = $this->isEncrypted() ? 3 : 2;
// only return points which are more recent than $oldestPointTime
foreach ($this->sessionData["points"] as $point) {
if (floatval($point[$timeIndex]) > $sinceTime) {
array_push($newPoints, $point);
}
}
return $newPoints;
}
}
// Generates a random session ID for new sessions.