Avoid reverse LIKE statements in SQL.
authorAntony Chazapis <chazapis@gmail.com>
Fri, 10 Feb 2012 18:43:59 +0000 (20:43 +0200)
committerAntony Chazapis <chazapis@gmail.com>
Fri, 10 Feb 2012 18:43:59 +0000 (20:43 +0200)
Refs #1984

pithos/backends/lib/sqlalchemy/permissions.py
pithos/backends/lib/sqlalchemy/xfeatures.py
pithos/backends/lib/sqlite/permissions.py
pithos/backends/lib/sqlite/xfeatures.py

index f6c74e5..2e03c95 100644 (file)
@@ -115,9 +115,11 @@ class Permissions(XFeatures, Groups, Public):
     def access_inherit(self, path):
         """Return the paths influencing the access for path."""
         
-        r = self.xfeature_inherit(path)
-        if not r:
-            return []
+#         r = self.xfeature_inherit(path)
+#         if not r:
+#             return []
+#         # Compute valid.
+#         return [x[0] for x in r if x[0] in valid]
         
         # Only keep path components.
         parts = path.rstrip('/').split('/')
@@ -125,8 +127,9 @@ class Permissions(XFeatures, Groups, Public):
         for i in range(1, len(parts)):
             subp = '/'.join(parts[:i + 1])
             valid.append(subp)
-            valid.append(subp + '/')
-        return [x[0] for x in r if x[0] in valid]
+            if subp != path:
+                valid.append(subp + '/')
+        return [x for x in valid if self.xfeature_get(x)]
     
     def access_list_paths(self, member, prefix=None):
         """Return the list of paths granted to member."""
index f015d5e..2d530c9 100644 (file)
@@ -67,17 +67,17 @@ class XFeatures(DBWorker):
         
         metadata.create_all(self.engine)
     
-    def xfeature_inherit(self, path):
-        """Return the (path, feature) inherited by the path, or None."""
-        
-        s = select([self.xfeatures.c.path, self.xfeatures.c.feature_id])
-        s = s.where(self.xfeatures.c.path <= path)
-        #s = s.where(self.xfeatures.c.path.like(self.escape_like(path) + '%', escape='\\')) # XXX: Implement reverse and escape like...
-        s = s.order_by(desc(self.xfeatures.c.path))
-        r = self.conn.execute(s)
-        l = r.fetchall()
-        r.close()
-        return l
+#     def xfeature_inherit(self, path):
+#         """Return the (path, feature) inherited by the path, or None."""
+#         
+#         s = select([self.xfeatures.c.path, self.xfeatures.c.feature_id])
+#         s = s.where(self.xfeatures.c.path <= path)
+#         #s = s.where(self.xfeatures.c.path.like(self.escape_like(path) + '%', escape='\\')) # XXX: Implement reverse and escape like...
+#         s = s.order_by(desc(self.xfeatures.c.path))
+#         r = self.conn.execute(s)
+#         l = r.fetchall()
+#         r.close()
+#         return l
     
     def xfeature_get(self, path):
         """Return feature for path."""
index b9f729e..476aaf2 100644 (file)
@@ -112,9 +112,11 @@ class Permissions(XFeatures, Groups, Public):
     def access_inherit(self, path):
         """Return the paths influencing the access for path."""
         
-        r = self.xfeature_inherit(path)
-        if not r:
-            return []
+#         r = self.xfeature_inherit(path)
+#         if not r:
+#             return []
+#         # Compute valid.
+#         return [x[0] for x in r if x[0] in valid]
         
         # Only keep path components.
         parts = path.rstrip('/').split('/')
@@ -122,8 +124,9 @@ class Permissions(XFeatures, Groups, Public):
         for i in range(1, len(parts)):
             subp = '/'.join(parts[:i + 1])
             valid.append(subp)
-            valid.append(subp + '/')
-        return [x[0] for x in r if x[0] in valid]
+            if subp != path:
+                valid.append(subp + '/')
+        return [x for x in valid if self.xfeature_get(x)]
     
     def access_list_paths(self, member, prefix=None):
         """Return the list of paths granted to member."""
index cc71094..7d682d0 100644 (file)
@@ -61,15 +61,15 @@ class XFeatures(DBWorker):
                             foreign key (feature_id) references xfeatures(feature_id)
                             on delete cascade ) """)
     
-    def xfeature_inherit(self, path):
-        """Return the (path, feature) inherited by the path, or None."""
-        
-        q = ("select path, feature_id from xfeatures "
-             "where path <= ? "
-             "and ? like path || '%' " # XXX: Escape like...
-             "order by path desc")
-        self.execute(q, (path, path))
-        return self.fetchall()
+#     def xfeature_inherit(self, path):
+#         """Return the (path, feature) inherited by the path, or None."""
+#         
+#         q = ("select path, feature_id from xfeatures "
+#              "where path <= ? "
+#              "and ? like path || '%' " # XXX: Escape like...
+#              "order by path desc")
+#         self.execute(q, (path, path))
+#         return self.fetchall()
     
     def xfeature_get(self, path):
         """Return feature for path."""