Merge pull request #400 from owncloud/simplify-polling
Move ops sync to a separate method
This commit is contained in:
commit
5bcdb206ea
@ -142,9 +142,8 @@ class SessionController extends Controller{
|
||||
case 'sync_ops':
|
||||
$seqHead = (string) isset($args['seq_head']) ? $args['seq_head'] : null;
|
||||
if (!is_null($seqHead)){
|
||||
$ops = isset($args['client_ops']) ? $args['client_ops'] : null;
|
||||
$hasOps = is_array($ops) && count($ops)>0;
|
||||
|
||||
$ops = isset($args['client_ops']) ? $args['client_ops'] : array();
|
||||
|
||||
$op = new Db\Op();
|
||||
$currentHead = $op->getHeadSeq($esId);
|
||||
|
||||
@ -153,40 +152,10 @@ class SessionController extends Controller{
|
||||
} catch (\Exception $e){
|
||||
//Db error. Not critical
|
||||
}
|
||||
$response->setData(
|
||||
$session->syncOps($memberId, $currentHead, $seqHead, $ops)
|
||||
);
|
||||
|
||||
// TODO handle the case ($currentHead == "") && ($seqHead != "")
|
||||
if ($seqHead == $currentHead) {
|
||||
// matching heads
|
||||
if ($hasOps) {
|
||||
// incoming ops without conflict
|
||||
// Add incoming ops, respond with a new head
|
||||
$newHead = Db\Op::addOpsArray($esId, $memberId, $ops);
|
||||
$response->setData(
|
||||
array(
|
||||
'result' => 'added',
|
||||
'head_seq' => $newHead ? $newHead : $currentHead
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// no incoming ops (just checking for new ops...)
|
||||
$response->setData(
|
||||
array(
|
||||
'result' => 'new_ops',
|
||||
'ops' => array(),
|
||||
'head_seq' => $currentHead
|
||||
)
|
||||
);
|
||||
}
|
||||
} else { // HEADs do not match
|
||||
$response->setData(
|
||||
array(
|
||||
'result' => $hasOps ? 'conflict' : 'new_ops',
|
||||
'ops' => $op->getOpsAfterJson($esId, $seqHead),
|
||||
'head_seq' => $currentHead,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$inactiveMembers = $member->updateByTimeout($esId);
|
||||
foreach ($inactiveMembers as $inactive){
|
||||
$op->removeCursor($esId, $inactive);
|
||||
|
@ -120,6 +120,41 @@ class Session extends \OCA\Documents\Db {
|
||||
$op->deleteBy('es_id', $esId);
|
||||
}
|
||||
|
||||
|
||||
public function syncOps($memberId, $currentHead, $clientHead, $clientOps){
|
||||
$hasOps = count($clientOps)>0;
|
||||
$op = new \OCA\Documents\Db\Op();
|
||||
|
||||
// TODO handle the case ($currentHead == "") && ($seqHead != "")
|
||||
if ($clientHead == $currentHead) {
|
||||
// matching heads
|
||||
if ($hasOps) {
|
||||
// incoming ops without conflict
|
||||
// Add incoming ops, respond with a new head
|
||||
$newHead = \OCA\Documents\Db\Op::addOpsArray($this->getEsId(), $memberId, $clientOps);
|
||||
$result = array(
|
||||
'result' => 'added',
|
||||
'head_seq' => $newHead ? $newHead : $currentHead
|
||||
);
|
||||
} else {
|
||||
// no incoming ops (just checking for new ops...)
|
||||
$result = array(
|
||||
'result' => 'new_ops',
|
||||
'ops' => array(),
|
||||
'head_seq' => $currentHead
|
||||
);
|
||||
}
|
||||
} else { // HEADs do not match
|
||||
$result = array(
|
||||
'result' => $hasOps ? 'conflict' : 'new_ops',
|
||||
'ops' => $op->getOpsAfterJson($this->getEsId(), $clientHead),
|
||||
'head_seq' => $currentHead,
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function insert(){
|
||||
$esId = $this->getUniqueSessionId();
|
||||
array_unshift($this->data, $esId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user