Revision cf4a7a7b snf-pithos-backend/pithos/backends/lib/sqlite/node.py
b/snf-pithos-backend/pithos/backends/lib/sqlite/node.py | ||
---|---|---|
207 | 207 |
""" |
208 | 208 |
|
209 | 209 |
placeholders = ','.join('?' for path in paths) |
210 |
q = "select path, node from nodes where path in (%s)" % placeholders
|
|
210 |
q = "select node from nodes where path in (%s)" % placeholders |
|
211 | 211 |
self.execute(q, paths) |
212 |
return self.fetchall() |
|
212 |
r = self.fetchall() |
|
213 |
if r is not None: |
|
214 |
return [row[0] for row in r] |
|
215 |
return None |
|
213 | 216 |
|
214 | 217 |
def node_get_properties(self, node): |
215 | 218 |
"""Return the node's (parent, path). |
... | ... | |
492 | 495 |
self.statistics_update_ancestors(node, 1, size, mtime, cluster) |
493 | 496 |
return serial, mtime |
494 | 497 |
|
495 |
def version_lookup(self, node, before=inf, cluster=0): |
|
498 |
def version_lookup(self, node, before=inf, cluster=0, all_props=True):
|
|
496 | 499 |
"""Lookup the current version of the given node. |
497 | 500 |
Return a list with its properties: |
498 | 501 |
(serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster) |
499 | 502 |
or None if the current version is not found in the given cluster. |
500 | 503 |
""" |
501 | 504 |
|
502 |
q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster "
|
|
505 |
q = ("select %s "
|
|
503 | 506 |
"from versions " |
504 | 507 |
"where serial = (select max(serial) " |
505 | 508 |
"from versions " |
506 | 509 |
"where node = ? and mtime < ?) " |
507 | 510 |
"and cluster = ?") |
511 |
if not all_props: |
|
512 |
q = q % "serial" |
|
513 |
else: |
|
514 |
q = q % "serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster" |
|
515 |
|
|
508 | 516 |
self.execute(q, (node, before, cluster)) |
509 | 517 |
props = self.fetchone() |
510 | 518 |
if props is not None: |
511 | 519 |
return props |
512 | 520 |
return None |
513 | 521 |
|
514 |
def version_lookup_bulk(self, nodes, before=inf, cluster=0): |
|
522 |
def version_lookup_bulk(self, nodes, before=inf, cluster=0, all_props=True):
|
|
515 | 523 |
"""Lookup the current versions of the given nodes. |
516 | 524 |
Return a list with their properties: |
517 | 525 |
(serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster). |
518 | 526 |
""" |
519 | 527 |
|
520 |
placeholders = ','.join('?' for node in nodes) |
|
521 |
q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster " |
|
528 |
q = ("select %s " |
|
522 | 529 |
"from versions " |
523 | 530 |
"where serial in (select max(serial) " |
524 | 531 |
"from versions " |
525 | 532 |
"where node in (%s) and mtime < ? group by node) " |
526 |
"and cluster = ?" % placeholders) |
|
533 |
"and cluster = ?") |
|
534 |
placeholders = ','.join('?' for node in nodes) |
|
535 |
if not all_props: |
|
536 |
q = q % ("serial", placeholders) |
|
537 |
else: |
|
538 |
q = q % ("serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster", placeholders) |
|
539 |
|
|
527 | 540 |
args = nodes |
528 | 541 |
args.extend((before, cluster)) |
529 | 542 |
self.execute(q, args) |
Also available in: Unified diff