[mirrorbrain-commits] r7969 - /trunk/mirrordoctor/mb/dbmaint.py

From: <poeml_at_mirrorbrain.org>
Date: Wed, 10 Mar 2010 00:06:11 -0000
Author: poeml
Date: Wed Mar 10 01:06:09 2010
New Revision: 7969

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7969&view=rev
Log:
mb db vacuum:
- The database cleanup now takes into account that files in the filearr table
  might not exist on any mirror, but locally - so they could be referenced in
  the hash table.

Modified:
    trunk/mirrordoctor/mb/dbmaint.py

Modified: trunk/mirrordoctor/mb/dbmaint.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/dbmaint.py?rev=7969&r1=7968&r2=7969&view=diff
==============================================================================
--- trunk/mirrordoctor/mb/dbmaint.py (original)
+++ trunk/mirrordoctor/mb/dbmaint.py Wed Mar 10 01:06:09 2010
_at_@ -5,6 +5,9 @@
     n_file_total = conn.Filearr.select().count()
 
     query = "SELECT count(*) FROM filearr WHERE mirrors = '{}'"
+    query = """SELECT count(*) FROM filearr 
+                   LEFT OUTER JOIN hash ON filearr.id = hash.file_id 
+               WHERE mirrors = '{}' AND hash.file_id IS NULL"""
     n_file_stale = conn.Filearr._connection.queryAll(query)[0]
 
 
_at_@ -16,7 +19,12 @@
     """delete stale file entries from the database"""
 
     print 'Deleting stale files...'
-    query = "DELETE FROM filearr WHERE mirrors = '{}'"
+    query = """DELETE FROM filearr 
+               WHERE id IN (
+                   SELECT filearr.id FROM filearr 
+                   LEFT OUTER JOIN hash ON filearr.id = hash.file_id 
+                   WHERE mirrors = '{}' AND hash.file_id IS NULL
+               )"""
     conn.Filearr._connection.query(query)
 
     print 'Done.'




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Wed Mar 10 2010 - 00:06:13 GMT

This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT