Commit 06ec7442 authored by sebastian's avatar sebastian

ZP-451 #comment normalize SyncParameters after unserializing, save...

ZP-451 #comment normalize SyncParameters after unserializing, save SyncParameters if updated and not invalidaded when replying with empty response in Sync, do not update FolderSyncRemaining counter with 0 if it's not set or already zero (prevent unecessary state update)


git-svn-id: https://z-push.org/svn/z-push/trunk@1952 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent b47fcb73
...@@ -347,8 +347,6 @@ class SyncParameters extends StateObject { ...@@ -347,8 +347,6 @@ class SyncParameters extends StateObject {
elseif (isset($this->contentParameters[self::TASKOPTIONS])) elseif (isset($this->contentParameters[self::TASKOPTIONS]))
$returnCPO = self::TASKOPTIONS; $returnCPO = self::TASKOPTIONS;
if ($returnCPO != $options)
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncParameters->normalizeType(): using %s for requested %s", $returnCPO, $options));
return $returnCPO; return $returnCPO;
} }
// something unexpected happened, just return default, empty in the worst case // something unexpected happened, just return default, empty in the worst case
...@@ -410,8 +408,9 @@ class SyncParameters extends StateObject { ...@@ -410,8 +408,9 @@ class SyncParameters extends StateObject {
* @return boolean * @return boolean
*/ */
protected function postUnserialize() { protected function postUnserialize() {
// init with default options // init with the available CPO or default
$this->UseCPO(); $availableCPO = $this->normalizeType(self::DEFAULTOPTIONS);
$this->UseCPO($availableCPO);
return true; return true;
} }
......
...@@ -623,13 +623,26 @@ class Sync extends RequestProcessor { ...@@ -623,13 +623,26 @@ class Sync extends RequestProcessor {
} }
} }
// in case there are no changes, we can reply with an empty response // in case there are no changes and no other request has synchronized while we waited, we can reply with an empty response
if (!$foundchanges && $status == SYNC_STATUS_SUCCESS){ if (!$foundchanges && $status == SYNC_STATUS_SUCCESS) {
ZLog::Write(LOGLEVEL_DEBUG, "No changes found. Replying with empty response and closing connection."); // if there were changes to the SPA or CPOs we need to save this before we terminate
// only save if the state was not modified by some other request, if so, return state invalid status
foreach($sc as $folderid => $spa) {
if (self::$deviceManager->CheckHearbeatStateIntegrity($spa->GetFolderId(), $spa->GetUuid(), $spa->GetUuidCounter())) {
$status = SYNC_COMMONSTATUS_SYNCSTATEVERSIONINVALID;
}
else {
$sc->SaveCollection($spa);
}
}
if ($status == SYNC_STATUS_SUCCESS) {
ZLog::Write(LOGLEVEL_DEBUG, "No changes found and no other process changed states. Replying with empty response and closing connection.");
self::$specialHeaders = array(); self::$specialHeaders = array();
self::$specialHeaders[] = "Connection: close"; self::$specialHeaders[] = "Connection: close";
return true; return true;
} }
}
if ($foundchanges) { if ($foundchanges) {
foreach ($sc->GetChangedFolderIds() as $folderid => $changecount) { foreach ($sc->GetChangedFolderIds() as $folderid => $changecount) {
...@@ -928,8 +941,10 @@ class Sync extends RequestProcessor { ...@@ -928,8 +941,10 @@ class Sync extends RequestProcessor {
self::$encoder->endTag(); self::$encoder->endTag();
self::$topCollector->AnnounceInformation(sprintf("Outgoing %d objects%s", $n, ($n >= $windowSize)?" of ".$changecount:""), true); self::$topCollector->AnnounceInformation(sprintf("Outgoing %d objects%s", $n, ($n >= $windowSize)?" of ".$changecount:""), true);
// update folder status // update folder status, if there is something set
if ($spa->GetFolderSyncRemaining() && $changecount > 0) {
$spa->SetFolderSyncRemaining($changecount); $spa->SetFolderSyncRemaining($changecount);
}
// changecount is initialized with 'false', so 0 means no changes! // changecount is initialized with 'false', so 0 means no changes!
if ($changecount === 0 || ($changecount !== false && $changecount <= $windowSize)) if ($changecount === 0 || ($changecount !== false && $changecount <= $windowSize))
self::$deviceManager->SetFolderSyncStatus($folderid, DeviceManager::FLD_SYNC_COMPLETED); self::$deviceManager->SetFolderSyncStatus($folderid, DeviceManager::FLD_SYNC_COMPLETED);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment