diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-12 15:13:53 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-12 15:13:53 (GMT) |
commit | 9108cb5aba91ae30dd5ad5534ec6407ebc54f7df (patch) | |
tree | cf213c0050cef35cee9808db324d0d72be440d66 | |
parent | 334359b1cabcd99afbcc34658c2e3f82523a5d50 (diff) |
Remove client side content changes tracking using seqno, client should rely on mtime which more appropriate for HTTP
-rw-r--r-- | active_document/directory.py | 9 | ||||
-rw-r--r-- | active_document/index.py | 2 | ||||
-rw-r--r-- | active_document/volume.py | 4 | ||||
-rw-r--r-- | active_toolkit/util.py | 5 | ||||
-rwxr-xr-x | tests/units/volume.py | 20 |
5 files changed, 23 insertions, 17 deletions
diff --git a/active_document/directory.py b/active_document/directory.py index c0fd242..8af5aa4 100644 --- a/active_document/directory.py +++ b/active_document/directory.py @@ -74,6 +74,10 @@ class Directory(object): _logger.debug('Initiated %r document', document_class) + @property + def mtime(self): + return self._index.mtime + def close(self): """Flush index write pending queue and close the index.""" self._index.close() @@ -249,7 +253,7 @@ class Directory(object): if found: self._save_layout() self.commit() - self._notify({'event': 'populate', 'seqno': self._seqno.value}) + self._notify({'event': 'populate'}) def diff(self, accept_range, limit): """Return documents' properties for specified times range. @@ -370,7 +374,6 @@ class Directory(object): def _post_store(self, guid, changes, event, increment_seqno): if event: - event['seqno'] = self._seqno.value self._notify(event) def _post_delete(self, guid, event): @@ -379,7 +382,7 @@ class Directory(object): def _post_commit(self): self._seqno.commit() - self._notify({'event': 'commit', 'seqno': self._seqno.value}) + self._notify({'event': 'commit'}) def _post(self, guid, props, new): for prop_name, value in props.items(): diff --git a/active_document/index.py b/active_document/index.py index d0a0f98..67ed083 100644 --- a/active_document/index.py +++ b/active_document/index.py @@ -56,7 +56,7 @@ class IndexReader(object): def mtime(self): """UNIX seconds of the last `commit()` call.""" if exists(self._mtime_path): - return os.stat(self._mtime_path).st_mtime + return int(os.stat(self._mtime_path).st_mtime) else: return 0 diff --git a/active_document/volume.py b/active_document/volume.py index 7e9e166..5da9f44 100644 --- a/active_document/volume.py +++ b/active_document/volume.py @@ -161,8 +161,10 @@ class VolumeCommands(CommandsProcessor): permissions=env.ACCESS_AUTH | env.ACCESS_AUTHOR) def update(self, request): with self._post(request, env.ACCESS_WRITE) as (directory, doc): + modified = bool(doc.props) self.before_update(request, doc.props) - directory.update(doc.guid, doc.props) + if modified: + directory.update(doc.guid, doc.props) @property_command(method='PUT', permissions=env.ACCESS_AUTH | env.ACCESS_AUTHOR) diff --git a/active_toolkit/util.py b/active_toolkit/util.py index b5646e2..0b7db93 100644 --- a/active_toolkit/util.py +++ b/active_toolkit/util.py @@ -17,14 +17,13 @@ $Repo: git://git.sugarlabs.org/alsroot/codelets.git$ $File: src/util.py$ -$Date: 2012-08-05$ +$Date: 2012-10-09$ """ import os import sys import logging -import subprocess from os.path import exists, join, islink, isdir, dirname, basename, abspath @@ -146,6 +145,8 @@ def call(cmd, stdin=None, asserts=False, raw=False, error_cb=None, **kwargs): `None` on errors, otherwise `str` value of stdout """ + import subprocess + stdout, stderr = None, None returncode = 1 try: diff --git a/tests/units/volume.py b/tests/units/volume.py index e9577b0..ffde031 100755 --- a/tests/units/volume.py +++ b/tests/units/volume.py @@ -169,7 +169,7 @@ class VolumeTest(tests.Test): blob_path = tests.tmpdir + '/testdocument/%s/%s/blob' % (guid[:2], guid) blob_meta = { - 'seqno': 3, + 'seqno': 2, 'path': blob_path + '.blob', 'digest': hashlib.sha1('blob').hexdigest(), 'mime_type': 'application/octet-stream', @@ -741,8 +741,8 @@ class VolumeTest(tests.Test): volume.populate() self.assertEqual([ - {'event': 'commit', 'document': 'document1', 'seqno': 0}, - {'event': 'populate', 'document': 'document1', 'seqno': 0}, + {'event': 'commit', 'document': 'document1'}, + {'event': 'populate', 'document': 'document1'}, ], events) del events[:] @@ -750,14 +750,14 @@ class VolumeTest(tests.Test): volume['document1'].create(guid='guid1') volume['document2'].create(guid='guid2') self.assertEqual([ - {'event': 'create', 'document': 'document1', 'seqno': 1, 'guid': 'guid1', 'props': { + {'event': 'create', 'document': 'document1', 'guid': 'guid1', 'props': { 'ctime': 0, 'mtime': 0, 'seqno': 0, 'prop': '', 'guid': 'guid1', }}, - {'event': 'create', 'document': 'document2', 'seqno': 2, 'guid': 'guid2', 'props': { + {'event': 'create', 'document': 'document2', 'guid': 'guid2', 'props': { 'ctime': 0, 'mtime': 0, 'seqno': 0, @@ -771,10 +771,10 @@ class VolumeTest(tests.Test): volume['document1'].update('guid1', prop='foo') volume['document2'].update('guid2', prop='bar') self.assertEqual([ - {'event': 'update', 'document': 'document1', 'seqno': 3, 'guid': 'guid1', 'props': { + {'event': 'update', 'document': 'document1', 'guid': 'guid1', 'props': { 'prop': 'foo', }}, - {'event': 'update', 'document': 'document2', 'seqno': 4, 'guid': 'guid2', 'props': { + {'event': 'update', 'document': 'document2', 'guid': 'guid2', 'props': { 'prop': 'bar', }}, ], @@ -783,7 +783,7 @@ class VolumeTest(tests.Test): volume['document2'].set_blob('guid2', 'blob', StringIO('blob')) self.assertEqual([ - {'event': 'update', 'document': 'document2', 'seqno': 5, 'guid': 'guid2', 'props': { + {'event': 'update', 'document': 'document2', 'guid': 'guid2', 'props': { 'seqno': 5, }}, ], @@ -801,8 +801,8 @@ class VolumeTest(tests.Test): volume['document2'].commit() self.assertEqual([ - {'event': 'commit', 'document': 'document1', 'seqno': 5}, - {'event': 'commit', 'document': 'document2', 'seqno': 5}, + {'event': 'commit', 'document': 'document1'}, + {'event': 'commit', 'document': 'document2'}, ], events) |