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

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py
219 219
            return row[0]
220 220
        return None
221 221
    
222
    def node_lookup_bulk(self, paths):
223
        """Lookup the current nodes for the given paths.
224
           Return () if the path is not found.
225
        """
226
        
227
        # Use LIKE for comparison to avoid MySQL problems with trailing spaces.
228
        s = select([self.nodes.c.node], self.nodes.c.path.in_(paths))
229
        r = self.conn.execute(s)
230
        rows = r.fetchall()
231
        r.close()
232
        return [row[0] for row in rows]
233
    
222 234
    def node_get_properties(self, node):
223 235
        """Return the node's (parent, path).
224 236
           Return None if the node is not found.
......
571 583
        self.statistics_update_ancestors(node, 1, size, mtime, cluster)
572 584
        return serial, mtime
573 585
    
574
    def version_lookup(self, node, before=inf, cluster=0):
586
    def version_lookup(self, node, before=inf, cluster=0, all_props=True):
575 587
        """Lookup the current version of the given node.
576 588
           Return a list with its properties:
577 589
           (serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster)
......
579 591
        """
580 592
        
581 593
        v = self.versions.alias('v')
582
        s = select([v.c.serial, v.c.node, v.c.hash,
583
                    v.c.size, v.c.type, v.c.source,
584
                    v.c.mtime, v.c.muser, v.c.uuid,
585
                    v.c.checksum, v.c.cluster])
594
        if not all_props:
595
            s = select([v.c.serial])
596
        else:
597
            s = select([v.c.serial, v.c.node, v.c.hash,
598
                        v.c.size, v.c.type, v.c.source,
599
                        v.c.mtime, v.c.muser, v.c.uuid,
600
                        v.c.checksum, v.c.cluster])
586 601
        c = select([func.max(self.versions.c.serial)],
587 602
            self.versions.c.node == node)
588 603
        if before != inf:
......
596 611
            return props
597 612
        return None
598 613
    
614
    def version_lookup_bulk(self, nodes, before=inf, cluster=0, all_props=True):
615
        """Lookup the current versions of the given nodes.
616
           Return a list with their properties:
617
           (serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster).
618
        """
619
        
620
        v = self.versions.alias('v')
621
        if not all_props:
622
            s = select([v.c.serial])
623
        else:
624
            s = select([v.c.serial, v.c.node, v.c.hash,
625
                        v.c.size, v.c.type, v.c.source,
626
                        v.c.mtime, v.c.muser, v.c.uuid,
627
                        v.c.checksum, v.c.cluster])
628
        c = select([func.max(self.versions.c.serial)],
629
            self.versions.c.node.in_(nodes)).group_by(self.versions.c.node)
630
        if before != inf:
631
            c = c.where(self.versions.c.mtime < before)
632
        s = s.where(and_(v.c.serial.in_(c),
633
                         v.c.cluster == cluster))
634
        r = self.conn.execute(s)
635
        rproxy = r.fetchall()
636
        r.close()
637
        return (tuple(row.values()) for row in rproxy)
638
        
599 639
    def version_get_properties(self, serial, keys=(), propnames=_propnames):
600 640
        """Return a sequence of values for the properties of
601 641
           the version specified by serial and the keys, in the order given.

Also available in: Unified diff