[Secure-testing-commits] r16579 - bin

Florian Weimer fw at alioth.debian.org
Sun Apr 24 15:09:27 UTC 2011


Author: fw
Date: 2011-04-24 15:09:25 +0000 (Sun, 24 Apr 2011)
New Revision: 16579

Modified:
   bin/list-queue
Log:
bin/list-queue: slightly unify cache expiry and update


Modified: bin/list-queue
===================================================================
--- bin/list-queue	2011-04-24 15:02:36 UTC (rev 16578)
+++ bin/list-queue	2011-04-24 15:09:25 UTC (rev 16579)
@@ -110,25 +110,32 @@
         result[name] = (size, mtime, dist, set(debs.split()))
     return result
 
-def computeupdate(ondisk, indb):
-    return [(path, stat) for (path, stat) in ondisk.items()
-            if path not in indb or stat <> tuple(indb[path][0:2])]
+def deletepaths(db, table, paths):
+    db.executemany("DELETE FROM " + table + " WHERE path = ?", paths)
 
+def prepareupdate(db, ondisk, indb, table):
+    need_update = [(path, stat) for (path, stat) in ondisk.items()
+                   if path not in indb or stat <> tuple(indb[path][0:2])]
+    db.executemany("DELETE FROM " + table + " WHERE path = ?",
+                   ((path,) for path, _ in need_update))
+    return need_update
+
+def expire(db, ondisk, indb, table):
+    need_delete = [(path,) for path in indb if path not in ondisk]
+    db.executemany("DELETE FROM " + table + " WHERE path = ?", need_delete)
+    for (path,) in need_delete:
+        del indb[path]
+
 def updatepackages(db, ondisk):
     """Updates the package table from the file system.
 
     Returns the current list of package objects, in arbitary order.
     """
     indb = readpackages(db)
-
-    # Expire old entries
-    need_delete = ((path,) for path in indb if path not in ondisk)
-    db.executemany("DELETE FROM package WHERE path = ?", need_delete)
+    expire(db, ondisk, indb, "package")
     
     # Update the cache in indb and the database
-    need_update = computeupdate(ondisk, indb)
-    db.executemany("DELETE FROM package WHERE path = ?",
-                   ((path,) for path, _ in need_update))
+    need_update = prepareupdate(db, ondisk, indb, "package")
     def do_update():
         for (path, stat) in need_update:
             deb = DebFile(path)
@@ -149,15 +156,10 @@
     Change objects are pairs (DISTRIBUTION, SET-OF-DEBS)
     """
     indb = readchanges(db)
+    expire(db, ondisk, indb, "changes")
 
-    # Expire old entries
-    need_delete = ((path,) for path in indb if path not in ondisk)
-    db.executemany("DELETE FROM changes WHERE path = ?", need_delete)
-    
     # Update the cache in indb and the database
-    need_update = computeupdate(ondisk, indb)
-    db.executemany("DELETE FROM changes WHERE path = ?",
-                   ((path,) for path, _ in need_update))
+    need_update = prepareupdate(db, ondisk, indb, "changes")
     def do_update():
         for (path, stat) in need_update:
             changes = Changes(file(path))




More information about the Secure-testing-commits mailing list