[rygel] tracker: Delete stale place-holder items



commit f77a13222b9b27fd22f158b624a0b61e0e4fa81e
Author: Jens Georg <mail jensge org>
Date:   Fri Jul 1 13:03:53 2011 +0200

    tracker: Delete stale place-holder items

 src/plugins/tracker/Makefile.am                    |    1 +
 .../rygel-tracker-category-all-container.vala      |    3 +
 .../tracker/rygel-tracker-cleanup-query.vala       |   62 ++++++++++++++++++++
 3 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/tracker/Makefile.am b/src/plugins/tracker/Makefile.am
index 90a396b..7596c2c 100644
--- a/src/plugins/tracker/Makefile.am
+++ b/src/plugins/tracker/Makefile.am
@@ -25,6 +25,7 @@ librygel_tracker_la_SOURCES = \
 	rygel-tracker-selection-query.vala \
 	rygel-tracker-deletion-query.vala \
 	rygel-tracker-insertion-query.vala \
+	rygel-tracker-cleanup-query.vala \
 	rygel-tracker-query-triplet.vala \
 	rygel-tracker-query-triplets.vala \
 	rygel-tracker-query-filter.vala \
diff --git a/src/plugins/tracker/rygel-tracker-category-all-container.vala b/src/plugins/tracker/rygel-tracker-category-all-container.vala
index d848939..55b1156 100644
--- a/src/plugins/tracker/rygel-tracker-category-all-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-all-container.vala
@@ -74,6 +74,9 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer,
                                      this.item_factory.category_iri,
                                      DBusSignalFlags.NONE,
                                      this.on_graph_updated);
+
+        var cleanup_query = new CleanupQuery (this.item_factory.category);
+        cleanup_query.execute (this.resources);
     }
 
     public async void add_item (MediaItem item, Cancellable? cancellable)
diff --git a/src/plugins/tracker/rygel-tracker-cleanup-query.vala b/src/plugins/tracker/rygel-tracker-cleanup-query.vala
new file mode 100644
index 0000000..460876e
--- /dev/null
+++ b/src/plugins/tracker/rygel-tracker-cleanup-query.vala
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation.
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Gee;
+
+/**
+ * Represents Tracker SPARQL Deletion query
+ */
+public class Rygel.Tracker.CleanupQuery : Query {
+    private string category;
+
+    public CleanupQuery (string category) {
+        var triplets = new QueryTriplets ();
+        triplets.add (new QueryTriplet ("?r", "a", "rdfs:Resource"));
+
+        base (triplets);
+
+        this.category = category;
+    }
+
+    public override async void execute (ResourcesIface resources)
+                                        throws IOError, DBusError {
+        var str = this.to_string ();
+
+        debug ("Executing SPARQL query: %s", str);
+
+        yield resources.sparql_update (str);
+    }
+
+    public override string to_string () {
+        StringBuilder result = new StringBuilder ();
+
+        result.append ("DELETE {");
+        result.append (base.to_string ());
+        result.append ("} WHERE {");
+        result.append_printf ("?r a nie:DataObject, %s . ", this.category);
+        result.append (" ?r nie:generator \"rygel\". ");
+        result.append ("FILTER(NOT EXISTS { ?r ");
+        result.append ("a nfo:FileDataObject. })}");
+
+        return result.str;
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]