Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-06-02 05:09:00 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-06-02 05:09:00 (GMT)
commit284b7b9f03a27317793c7ae000b9f03a062e5243 (patch)
tree6714e193166c13902c26b3b16266e321c5c425b3
parentcc35175e8ee90a203cd92bd91046578228da0846 (diff)
Do not lazy open client SN db
It should affect startup speed since local db is mostly empty. At the same time, lazy open breaks offline push logic.
-rwxr-xr-xsugar-network-client2
-rw-r--r--sugar_network/client/__init__.py7
-rw-r--r--sugar_network/db/volume.py14
-rw-r--r--sugar_network/resources/volume.py4
-rwxr-xr-xtests/units/db/volume.py27
-rwxr-xr-xtests/units/resources/volume.py2
6 files changed, 9 insertions, 47 deletions
diff --git a/sugar-network-client b/sugar-network-client
index be02796..0d1d8f8 100755
--- a/sugar-network-client
+++ b/sugar-network-client
@@ -104,7 +104,7 @@ class Application(application.Daemon):
def run(self):
util.ensure_key(client.key_path())
- volume = Volume(client.path('db'), lazy_open=client.lazy_open.value)
+ volume = Volume(client.path('db'))
commands = CachedClientCommands(volume,
client.api_url.value if not client.server_mode.value else None)
diff --git a/sugar_network/client/__init__.py b/sugar_network/client/__init__.py
index 65e3a53..109c6a8 100644
--- a/sugar_network/client/__init__.py
+++ b/sugar_network/client/__init__.py
@@ -90,10 +90,6 @@ mounts_root = Option(
'path to a directory with remote devices mounts',
default='/media')
-lazy_open = Option(
- 'do not open all indexes at once on startup',
- default=False, type_cast=Option.bool_cast, action='store_true')
-
ipc_port = Option(
'port number to listen for incomming connections from IPC clients',
default=5001, type_cast=int, name='ipc_port')
@@ -188,8 +184,7 @@ def IPCRouter(*args, **kwargs):
class _IPCRouter(Router):
def authenticate(self, request):
- if not anonymous.value:
- return sugar_uid()
+ pass
def call(self, request, response):
request.access_level = db.ACCESS_LOCAL
diff --git a/sugar_network/db/volume.py b/sugar_network/db/volume.py
index 34cb671..8c248b0 100644
--- a/sugar_network/db/volume.py
+++ b/sugar_network/db/volume.py
@@ -42,7 +42,7 @@ class Volume(dict):
_flush_pool = []
- def __init__(self, root, documents, index_class=None, lazy_open=False):
+ def __init__(self, root, documents, index_class=None):
Volume._flush_pool.append(self)
if index_class is None:
@@ -55,7 +55,6 @@ class Volume(dict):
os.makedirs(root)
self._index_class = index_class
self._subscriptions = {}
- self._to_open = {}
self.seqno = util.Seqno(join(self._root, 'seqno'))
for document in documents:
@@ -63,10 +62,7 @@ class Volume(dict):
name = document.split('.')[-1]
else:
name = document.__name__.lower()
- if lazy_open:
- self._to_open[name] = document
- else:
- self[name] = self._open(name, document)
+ self[name] = self._open(name, document)
@property
def root(self):
@@ -111,10 +107,8 @@ class Volume(dict):
def __getitem__(self, name):
directory = self.get(name)
- if directory is None:
- enforce(name in self._to_open, http.BadRequest,
- 'Unknown %r document', name)
- directory = self[name] = self._open(name, self._to_open.pop(name))
+ enforce(directory is not None, http.BadRequest,
+ 'Unknown %r document', name)
return directory
def _open(self, name, document):
diff --git a/sugar_network/resources/volume.py b/sugar_network/resources/volume.py
index 7c29fa6..f71b2dc 100644
--- a/sugar_network/resources/volume.py
+++ b/sugar_network/resources/volume.py
@@ -136,11 +136,11 @@ class Volume(db.Volume):
'sugar_network.resources.user',
)
- def __init__(self, root, document_classes=None, lazy_open=False):
+ def __init__(self, root, document_classes=None):
if document_classes is None:
document_classes = Volume.RESOURCES
self._populators = coroutine.Pool()
- db.Volume.__init__(self, root, document_classes, lazy_open=lazy_open)
+ db.Volume.__init__(self, root, document_classes)
def close(self):
self._populators.kill()
diff --git a/tests/units/db/volume.py b/tests/units/db/volume.py
index d154e27..5ffd262 100755
--- a/tests/units/db/volume.py
+++ b/tests/units/db/volume.py
@@ -430,33 +430,6 @@ class VolumeTest(tests.Test):
[{'localized_prop': 'value_%s' % fallback_lang}],
self.call('GET', document='testdocument', accept_language=['foo', 'fr', 'za'], reply=['localized_prop'])['result'])
- def test_LazyOpen(self):
-
- class Document1(db.Document):
- pass
-
- class Document2(db.Document):
- pass
-
- volume = db.Volume('.', [Document1, Document2], lazy_open=True)
- assert not exists('document1/index')
- assert not exists('document2/index')
- volume['document1'].find()
- volume['document2'].find()
- assert exists('document1/index')
- assert exists('document2/index')
- volume['document1'].find()
- volume['document2'].find()
- volume.close()
-
- shutil.rmtree('document1')
- shutil.rmtree('document2')
-
- volume = db.Volume('.', [Document1, Document2], lazy_open=False)
- assert exists('document1/index')
- assert exists('document2/index')
- volume.close()
-
def test_OpenByModuleName(self):
self.touch(
('foo/bar.py', [
diff --git a/tests/units/resources/volume.py b/tests/units/resources/volume.py
index bbcb444..1e5b6ca 100755
--- a/tests/units/resources/volume.py
+++ b/tests/units/resources/volume.py
@@ -138,7 +138,7 @@ class VolumeTest(tests.Test):
('db/context/1/1/description', json.dumps({"value": {}})),
)
- volume = Volume('db', lazy_open=True)
+ volume = Volume('db')
cp = TestCommands(volume)
assert not exists('db/context/index')