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

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py
309 309
    def node_purge_children(self, parent, before=inf, cluster=0):
310 310
        """Delete all versions with the specified
311 311
           parent and cluster, and return
312
           the hashes and size of versions deleted.
312
           the hashes, the total size and the serials of versions deleted.
313 313
           Clears out nodes with no remaining versions.
314 314
        """
315 315
        #update statistics
......
317 317
                    self.nodes.c.parent == parent)
318 318
        where_clause = and_(self.versions.c.node.in_(c1),
319 319
                            self.versions.c.cluster == cluster)
320
        if before != inf:
321
            where_clause = and_(where_clause,
322
                                self.versions.c.mtime <= before)
320 323
        s = select([func.count(self.versions.c.serial),
321 324
                    func.sum(self.versions.c.size)])
322 325
        s = s.where(where_clause)
323
        if before != inf:
324
            s = s.where(self.versions.c.mtime <= before)
325 326
        r = self.conn.execute(s)
326 327
        row = r.fetchone()
327 328
        r.close()
328 329
        if not row:
329 330
            return (), 0, ()
330
        nr, size = row[0], -row[1] if row[1] else 0
331
        nr, size = row[0], row[1] if row[1] else 0
331 332
        mtime = time()
332
        self.statistics_update(parent, -nr, size, mtime, cluster)
333
        self.statistics_update_ancestors(parent, -nr, size, mtime, cluster)
333
        self.statistics_update(parent, -nr, -size, mtime, cluster)
334
        self.statistics_update_ancestors(parent, -nr, -size, mtime, cluster)
334 335

  
335 336
        s = select([self.versions.c.hash, self.versions.c.serial])
336 337
        s = s.where(where_clause)
......
373 374
                    func.sum(self.versions.c.size)])
374 375
        where_clause = and_(self.versions.c.node == node,
375 376
                            self.versions.c.cluster == cluster)
376
        s = s.where(where_clause)
377 377
        if before != inf:
378
            s = s.where(self.versions.c.mtime <= before)
378
            where_clause = and_(where_clause,
379
                                self.versions.c.mtime <= before)
380
        s = s.where(where_clause)
379 381
        r = self.conn.execute(s)
380 382
        row = r.fetchone()
381 383
        nr, size = row[0], row[1]
......
405 407
                   and_(self.nodes.c.node == node,
406 408
                        select([func.count(self.versions.c.serial)],
407 409
                               self.versions.c.node == self.nodes.c.node).as_scalar() == 0))
408
        r = self.conn.execute(s)
409
        nodes = r.fetchall()
410
        r.close()
410
        rp= self.conn.execute(s)
411
        nodes = [r[0] for r in rp.fetchall()]
412
        rp.close()
411 413
        if nodes:
412 414
            s = self.nodes.delete().where(self.nodes.c.node.in_(nodes))
413 415
            self.conn.execute(s).close()

Also available in: Unified diff