Commit eed8b9e2 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: improve performance of get_domain_list

Before it used to query the database
for all the objects having the specific domain
and finally filtered out the objects to which the user had no access.
Now gets first the allowed_paths for the user and then
brings those having the specific domain

Refs: #3510
parent 44fef2e9
......@@ -1166,7 +1166,7 @@ class Node(DBWorker):
r.close()
return l
def domain_object_list(self, domain, cluster=None):
def domain_object_list(self, domain, paths, cluster=None):
"""Return a list of (path, property list, attribute dictionary)
for the objects in the specific domain and cluster.
"""
......@@ -1184,6 +1184,8 @@ class Node(DBWorker):
s = s.where(v.c.cluster == cluster)
s = s.where(v.c.serial == a.c.serial)
s = s.where(a.c.domain == domain)
if paths:
s = s.where(n.c.path.in_(paths))
r = self.conn.execute(s)
rows = r.fetchall()
......
......@@ -1039,7 +1039,7 @@ class Node(DBWorker):
self.execute(q, args)
return self.fetchone()
def domain_object_list(self, domain, cluster=None):
def domain_object_list(self, domain, paths, cluster=None):
"""Return a list of (path, property list, attribute dictionary)
for the objects in the specific domain and cluster.
"""
......@@ -1051,8 +1051,10 @@ class Node(DBWorker):
"where n.node = v.node and "
"n.latest_version = v.serial and "
"v.serial = a.serial and "
"a.domain = ? ")
"a.domain = ? and "
"n.path in (%s)" % ','.join(['?' for _ in range(len(paths))))
args = [domain]
map(args.append, paths)
if cluster != None:
q += "and v.cluster = ?"
args += [cluster]
......
......@@ -1592,14 +1592,15 @@ class ModularBackend(BaseBackend):
@backend_method
def get_domain_objects(self, domain, user=None):
obj_list = self.node.domain_object_list(domain, CLUSTER_NORMAL)
if user != None:
obj_list = [t for t in obj_list \
if self._has_read_access(user, t[0])]
allowed_paths = self.permissions.access_list_paths(user)
if not allowed_paths:
return []
obj_list = self.node.domain_object_list(
domain, allowed_paths, CLUSTER_NORMAL)
return [(path,
self._build_metadata(props, user_defined_meta),
self.permissions.access_get(path)) \
for path, props, user_defined_meta in obj_list]
self.permissions.access_get(path)) for
path, props, user_defined_meta in obj_list]
# util functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment