Revision b83df225 snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py
989 989
        a = self.attributes.alias('a')
990 990
        v = self.versions.alias('v')
991 991
        n = self.nodes.alias('n')
992
        s = select([a.c.key]).distinct()
992
        s = select([self.attributes.c.key]).distinct()
993 993
        if before != inf:
994 994
            filtered = select([func.max(self.versions.c.serial)])
995 995
            filtered = filtered.where(self.versions.c.mtime < before)
996
            filtered = filtered.where(self.versions.c.node == v.c.node)
996
            filtered = filtered.where(self.versions.c.node == \
997
			    self.versions.c.node)
997 998
        else:
998 999
            filtered = select([self.nodes.c.latest_version])
999
            filtered = filtered.where(self.nodes.c.node == v.c.node)
1000
        s = s.where(v.c.serial == filtered)
1001
        s = s.where(v.c.cluster != except_cluster)
1002
        s = s.where(v.c.node.in_(select([self.nodes.c.node],
1000
            filtered = filtered.where(self.nodes.c.node == \
1001
			    self.versions.c.node).correlate(self.versions)
1002
        s = s.where(self.versions.c.serial == filtered)
1003
        s = s.where(self.versions.c.cluster != except_cluster)
1004
        s = s.where(self.versions.c.node.in_(select([self.nodes.c.node],
1003 1005
                                        self.nodes.c.parent == parent)))
1004
        s = s.where(a.c.serial == v.c.serial)
1005
        s = s.where(a.c.domain == domain)
1006
        s = s.where(n.c.node == v.c.node)
1006
        s = s.where(self.attributes.c.serial == self.versions.c.serial)
1007
        s = s.where(self.attributes.c.domain == domain)
1008
        s = s.where(self.nodes.c.node == self.versions.c.node)
1007 1009
        conj = []
1008 1010
        for path, match in pathq:
1009 1011
            if match == MATCH_PREFIX:
1010
                conj.append(n.c.path.like(self.escape_like(path) + '%',
1012
                conj.append(self.nodes.c.path.like(self.escape_like(path) + '%',
1011 1013
                                          escape=ESCAPE_CHAR))
1012 1014
            elif match == MATCH_EXACT:
1013
                conj.append(n.c.path == path)
1015
                conj.append(self.nodes.c.path == path)
1014 1016
        if conj:
1015 1017
            s = s.where(or_(*conj))
1016 1018
        rp = self.conn.execute(s)
......
1087 1089
                            onclause=self.versions.c.serial==filtered)
1088 1090
        else:
1089 1091
            filtered = select([self.nodes.c.latest_version])
1092
            filtered = filtered.where(self.nodes.c.node == self.versions.c.node).correlate(self.versions)
1090 1093
            inner_join = \
1091 1094
                    self.nodes.join(self.versions,
1092 1095
                            onclause=\
1093
                            self.versions.c.serial==self.nodes.c.latest_version)
1096
                            self.versions.c.serial==filtered)
1094 1097
        if not all_props:
1095 1098
            s = select([self.nodes.c.path,
1096 1099
                self.versions.c.serial],from_obj=[inner_join]).distinct()
......
1107 1110

  
1108 1111
        s = s.where(self.versions.c.cluster != except_cluster)
1109 1112
        s = s.where(self.versions.c.node.in_(select([self.nodes.c.node],
1110
                                        self.nodes.c.parent == parent)))
1113
                                             self.nodes.c.parent == parent)))
1111 1114

  
1112 1115
        s = s.where(self.versions.c.node == self.nodes.c.node)
1113
        s = s.where(and_(self.nodes.c.path > bindparam('start'), self.nodes.c.path < nextling))
1114
        conja = []
1115
        conjb = []
1116
        s = s.where(and_(self.nodes.c.path > bindparam('start'),
1117
			 self.nodes.c.path < nextling))
1118
        conj = []
1116 1119
        for path, match in pathq:
1117 1120
            if match == MATCH_PREFIX:
1118
                conja.append(self.nodes.c.path.like(self.escape_like(path) + '%',
1119
                                          escape=ESCAPE_CHAR))
1121
                conj.append(self.nodes.c.path.like(self.escape_like(path) + '%',
1122
                             escape=ESCAPE_CHAR))
1120 1123
            elif match == MATCH_EXACT:
1121
                conjb.append(path)
1122
        if conja or conjb:
1123
            s = s.where(and_(self.nodes.c.path.in_(conjb),*conja))
1124
                conj.append(self.nodes.c.path == path)
1125
        if conj:
1126
            s = s.where(or_(*conj))
1124 1127

  
1125 1128
        if sizeq and len(sizeq) == 2:
1126 1129
            if sizeq[0]:
......
1133 1136
            included, excluded, opers = parse_filters(filterq)
1134 1137
            if included:
1135 1138
                subs = select([1])
1136
                subs = subs.where(a.c.serial == v.c.serial).correlate(v)
1137
                subs = subs.where(a.c.domain == domain)
1138
                subs = subs.where(or_(*[a.c.key.op('=')(x) for x in included]))
1139
                subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions)
1140
                subs = subs.where(self.attributes.c.domain == domain)
1141
                subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for x in included]))
1139 1142
                s = s.where(exists(subs))
1140 1143
            if excluded:
1141 1144
                subs = select([1])
1142
                subs = subs.where(a.c.serial == v.c.serial).correlate(v)
1143
                subs = subs.where(a.c.domain == domain)
1144
                subs = subs.where(or_(*[a.c.key.op('=')(x) for x in excluded]))
1145
                subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions)
1146
                subs = subs.where(self.attributes.c.domain == domain)
1147
                subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for x in excluded]))
1145 1148
                s = s.where(not_(exists(subs)))
1146 1149
            if opers:
1147 1150
                for k, o, val in opers:
1148 1151
                    subs = select([1])
1149
                    subs = subs.where(a.c.serial == v.c.serial).correlate(v)
1150
                    subs = subs.where(a.c.domain == domain)
1152
                    subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions)
1153
                    subs = subs.where(self.attributes.c.domain == domain)
1151 1154
                    subs = subs.where(
1152
                        and_(a.c.key.op('=')(k), a.c.value.op(o)(val)))
1155
                        and_(self.attributes.c.key.op('=')(k), self.attributes.c.value.op(o)(val)))
1153 1156
                    s = s.where(exists(subs))
1154 1157

  
1155 1158
        s = s.order_by(self.nodes.c.path)

Also available in: Unified diff