diff options
author | Kali Kaneko <kali@leap.se> | 2017-02-17 16:15:10 +0100 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-02-17 20:39:12 +0100 |
commit | bab34cde11bdeb2810cc9f5d223957af26b2b6d3 (patch) | |
tree | 8acfd20d312728b1016acddc73f815ac54f84898 /server/src | |
parent | 11416de633f355cbed1380404ef2807fd82b1e19 (diff) |
[refactor] create resources only once
it doesn't make sense to create the resources for every request, we can
reuse the same resource and create it in the constructor.
- Resolves: #8770
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/leap/soledad/server/_wsgi.py | 3 | ||||
-rw-r--r-- | server/src/leap/soledad/server/auth.py | 35 |
2 files changed, 18 insertions, 20 deletions
diff --git a/server/src/leap/soledad/server/_wsgi.py b/server/src/leap/soledad/server/_wsgi.py index 37a03ced..a719aacb 100644 --- a/server/src/leap/soledad/server/_wsgi.py +++ b/server/src/leap/soledad/server/_wsgi.py @@ -27,6 +27,8 @@ from leap.soledad.common.backend import SoledadBackend from leap.soledad.common.couch.state import CouchServerState from leap.soledad.common.log import getLogger +from twisted.logger import Logger +log = Logger() __all__ = ['init_couch_state', 'get_sync_resource'] @@ -62,6 +64,7 @@ def init_couch_state(conf): def get_sync_resource(pool=None): if not pool: + log.warn("NO POOL PASSED, CREATING----------") pool = threadpool.ThreadPool() reactor.callWhenRunning(pool.start) reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) diff --git a/server/src/leap/soledad/server/auth.py b/server/src/leap/soledad/server/auth.py index c52370cb..e064341b 100644 --- a/server/src/leap/soledad/server/auth.py +++ b/server/src/leap/soledad/server/auth.py @@ -51,30 +51,25 @@ class SoledadRealm(object): def __init__(self, conf=None, sync_pool=None): if not conf: conf = get_config() - self._conf = conf - self._sync_pool = sync_pool + blobs = conf['blobs'] + self.anon_resource = SoledadAnonResource( + enable_blobs=blobs) + self.auth_resource = SoledadResource( + enable_blobs=blobs, + sync_pool=sync_pool) def requestAvatar(self, avatarId, mind, *interfaces): - enable_blobs = self._conf['blobs'] # Anonymous access if IAnonymous.providedBy(avatarId): - resource = SoledadAnonResource( - enable_blobs=enable_blobs) - return (IResource, resource, lambda: None) - - # Authenticated users - - # TODO review this: #8770 ---------------- - # we're creating a Resource tree - # for each request, for every user. - # What are the perf implications of this?? - - if IResource in interfaces: - resource = SoledadResource( - enable_blobs=enable_blobs, - sync_pool=self._sync_pool) - return (IResource, resource, lambda: None) + return (IResource, self.anon_resource, + lambda: None) + + # Authenticated access + else: + if IResource in interfaces: + return (IResource, self.auth_resource, + lambda: None) raise NotImplementedError() @@ -165,7 +160,7 @@ class TokenCredentialFactory(object): raise error.LoginFailed('Invalid credentials') -def get_portal(sync_pool=None): +def portalFactory(sync_pool=None): realm = SoledadRealm(sync_pool=sync_pool) checker = TokenChecker() return Portal(realm, [checker]) |