diff artifact-database/src/main/resources/sql/org-postgresql-driver.properties @ 232:202b6ae2fcad

Database cleaner: Removes outdated collections, too. artifacts/trunk@1636 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 31 Mar 2011 17:14:22 +0000
parents 1ea35226a6de
children b35d32e507b6
line wrap: on
line diff
--- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Thu Mar 31 15:56:50 2011 +0000
+++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties	Thu Mar 31 17:14:22 2011 +0000
@@ -85,6 +85,15 @@
     WHERE ci.collection_id IN (SELECT id FROM collections WHERE gid = ?::uuid)
 
 # COLLECTIONS
+
+collections.outdated= \
+    SELECT c.id FROM collections c \
+        INNER JOIN collection_items ci ON c.id = ci.collection_id \
+        INNER JOIN artifacts        a  ON ci.artifact_id = a.id \
+        WHERE c.ttl IS NOT NULL \
+            AND CURRENT_TIMESTAMP - c.last_access > (c.ttl || ' microseconds')::interval \
+            AND a.id NOT IN ($LOCKED_IDS$)
+
 collections.touch.by.gid =\
     UPDATE collections SET last_access = CURRENT_TIMESTAMP \
         WHERE gid = ?::uuid

http://dive4elements.wald.intevation.org