Optimize SyncML performance

This commit is contained in:
Jörg Lehrke 2009-12-01 11:21:13 +00:00
parent fd884940f8
commit a1ee7d5cbf
7 changed files with 198 additions and 234 deletions

View File

@ -279,14 +279,6 @@ class Horde_SyncML_Command_Alert extends Horde_SyncML_Command {
return $currentCmdID;
}
// Store client's Next Anchor in State and
// set server's Next Anchor. After successful sync
// this is then written to persistence for negotiation of
// further syncs.
$state->setClientAnchorNext($type, $this->_metaAnchorNext);
$serverAnchorNext = time();
$state->setServerAnchorNext($type, $serverAnchorNext);
// Now set interval to retrieve server changes from, defined by
// ServerAnchor [Last,Next]
if ($synctype != ALERT_TWO_WAY &&
@ -313,6 +305,21 @@ class Horde_SyncML_Command_Alert extends Horde_SyncML_Command {
$sync->setsyncType($synctype);
$sync->setFilterExpression($this->_filterExpression);
$state->setSync($this->_targetLocURI, $sync);
$hordeType = $state->getHordeType($this->_targetLocURI);
$changes =& $registry->call($hordeType. '/listBy',
array('action' => 'modify',
'timestamp' => $serverAnchorLast,
'type' => $this->_targetLocURI,
'filter' => $this->_filterExpression));
$state->setChangedItems($this->_targetLocURI, $changes);
// Store client's Next Anchor in State and
// set server's Next Anchor. After successful sync
// this is then written to persistence for negotiation of
// further syncs.
$state->setClientAnchorNext($type, $this->_metaAnchorNext);
$serverAnchorNext = time();
$state->setServerAnchorNext($type, $serverAnchorNext);
$status = new Horde_SyncML_Command_Status($response, 'Alert');
$status->setCmdRef($this->_cmdID);

View File

@ -127,27 +127,33 @@ class Horde_SyncML_Command_Sync extends Horde_SyncML_Command {
function syncToClient($currentCmdID, &$output)
{
Horde::logMessage('SyncML: starting sync to client', __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML: starting sync to client',
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$state = &$_SESSION['SyncML.state'];
if($state->getSyncStatus() >= CLIENT_SYNC_FINNISHED && $state->getSyncStatus() < SERVER_SYNC_FINNISHED)
if ($state->getSyncStatus() >= CLIENT_SYNC_FINNISHED
&& $state->getSyncStatus() < SERVER_SYNC_FINNISHED)
{
$deviceInfo = $state->getClientDeviceInfo();
$targets = $state->getTargets();
foreach($targets as $target)
if (($targets = $state->getTargets())) {
foreach ($targets as $target)
{
$sync = &$state->getSync($target);
Horde::logMessage('SyncML['. session_id() .']: sync alerttype '. $sync->_syncType .' found for target ' . $target, __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML[' . session_id() . ']: sync alerttype ' .
$sync->_syncType . ' found for target ' . $target,
__FILE__, __LINE__, PEAR_LOG_DEBUG);
if ($sync->_syncType == ALERT_ONE_WAY_FROM_CLIENT ||
$sync->_syncType == ALERT_REFRESH_FROM_CLIENT) {
Horde::logMessage('SyncML['. session_id() .']: From client Sync, no sync of '. $target .' to client', __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML[' . session_id() .
']: From client Sync, no sync of ' . $target .
' to client', __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->clearSync($target);
} else if ($state->getSyncStatus() >= CLIENT_SYNC_ACKNOWLEDGED) {
} elseif ($state->getSyncStatus() >= CLIENT_SYNC_ACKNOWLEDGED) {
Horde::logMessage("SyncML: starting sync to client $target", __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage("SyncML: starting sync to client $target",
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$attrs = array();
$state->setSyncStatus(SERVER_SYNC_DATA_PENDING);
@ -192,22 +198,21 @@ class Horde_SyncML_Command_Sync extends Horde_SyncML_Command {
break;
}
} else {
Horde::logMessage("SyncML: Waiting for client ACKNOWLEDGE for $target", __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage("SyncML: Waiting for client ACKNOWLEDGE for $target",
__FILE__, __LINE__, PEAR_LOG_DEBUG);
}
}
}
// no syncs left
if($state->getTargets() === FALSE &&
if ($state->getTargets() === false &&
!isset($state->curSyncItem)) {
$state->setSyncStatus(SERVER_SYNC_FINNISHED);
}
Horde::logMessage('SyncML: syncStatus(syncToClient) = '. $state->getSyncStatus(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML: syncStatus(syncToClient) = ' .
$state->getSyncStatus(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
return $currentCmdID;
}
function endElement($uri, $element)

View File

@ -612,7 +612,7 @@ class Horde_SyncML_State {
function getTargets()
{
if(count($this->_syncs) < 1)
return FALSE;
return false;
foreach($this->_syncs as $target => $sync)
{

View File

@ -213,8 +213,9 @@ class EGW_SyncML_State extends Horde_SyncML_State
/**
* returns GUIDs of all client items
*/
function getClientItems() {
$mapID = $this->_locName . $this->_sourceURI . $this->_targetURI;
function getClientItems($type=false) {
if (!$type) $type = $this->_targetURI;
$mapID = $this->_locName . $this->_sourceURI . $type;
$guids = array();
foreach($GLOBALS['egw']->db->select('egw_contentmap', 'map_guid', array(

View File

@ -177,14 +177,8 @@ class Horde_SyncML_Sync {
$sourceURI = $state->getSourceURI();
$hordeType = $state->getHordeType($type);
$serverAnchorLast = $state->getServerAnchorLast($type);
$state->setTargetURI($type);
$changes = array();
// First we get all changes done after the previous sync start
foreach ($registry->call($hordeType. '/listBy',
array('action' => 'modify',
'timestamp' => $serverAnchorLast,
'type' => $type,
'filter' => $this->_filterExpression)) as $change) {
foreach($state->getChangedItems($type) as $change) {
// now we have to remove the ones
// that came from the last sync with this client
$guid_ts = $state->getSyncTSforAction($change, 'modify');

View File

@ -308,21 +308,11 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$hordeType = $state->getHordeType($syncType);
$state->setTargetURI($syncType);
$future = $state->getServerAnchorNext($syncType);
$delta_add = 0;
Horde::logMessage("SyncML: reading added items from database for $hordeType",
__FILE__, __LINE__, PEAR_LOG_DEBUG);
/* The items, which now match the filter criteria are show here, too
$delta_add = count($registry->call($hordeType. '/listBy',
array('action' => 'add',
'timestamp' => $future,
'type' => $syncType,
'filter' => $this->_filterExpression)));
*/
$state->mergeAddedItems($syncType, $registry->call($hordeType. '/list', array('filter' => $this->_filterExpression)));
$this->_syncDataLoaded = TRUE;
return count($state->getAddedItems($syncType)) - $delta_add + count($state->getConflictItems($syncType));
return count($state->getAddedItems($syncType)) + count($state->getConflictItems($syncType));
}
}

View File

@ -409,27 +409,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
$state = & $_SESSION['SyncML.state'];
$syncType = $this->_targetLocURI;
$hordeType = $state->getHordeType($syncType);
$state->setTargetURI($syncType);
$refts = $state->getServerAnchorLast($syncType);
$future = $state->getServerAnchorNext($syncType);
$delta_mod = 0;
$delta_add = 0;
Horde :: logMessage("SyncML: reading changed items from database for $hordeType",
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$delta_mod = count($registry->call($hordeType . '/listBy', array (
'action' => 'modify',
'timestamp' => $future,
'type' => $syncType,
'filter' => $this->_filterExpression
)));
$changedItems =& $registry->call($hordeType . '/listBy', array (
'action' => 'modify',
'timestamp' => $refts,
'type' => $syncType,
'filter' => $this->_filterExpression
));
$addedItems =& $registry->call($hordeType . '/listBy', array (
'action' => 'add',
@ -438,12 +419,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
'filter' => $this->_filterExpression
));
// added items may show up as changed, too
$changedItems = array_diff($changedItems, $addedItems);
$state->mergeChangedItems($syncType, $changedItems);
$state->mergeAddedItems($syncType, $addedItems);
$state->setAddedItems($syncType, $addedItems);
$state->setDeletedItems($syncType, $registry->call($hordeType . '/listBy', array (
'action' => 'delete',
@ -452,17 +428,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
'filter' => $this->_filterExpression
)));
/* The items, which now match the filter criteria are show here, too
$delta_add = count($registry->call($hordeType . '/listBy', array (
'action' => 'add',
'timestamp' => $future,
'type' => $syncType,
'filter' => $this->_filterExpression
)));
*/
$this->_syncDataLoaded = TRUE;
return count($state->getChangedItems($syncType)) - $delta_mod + count($state->getDeletedItems($syncType)) + count($state->getAddedItems($syncType)) - $delta_add + count($state->getConflictItems($syncType));
return count($state->getChangedItems($syncType)) + count($state->getDeletedItems($syncType)) + count($state->getAddedItems($syncType)) + count($state->getConflictItems($syncType));
}
}