[rygel] media-export: Simplify harvesting code



commit 01e1de5ae294eb8cfcecbfd3347072469cab6c4f
Author: Jens Georg <mail jensge org>
Date:   Thu May 13 16:26:40 2010 +0200

    media-export: Simplify harvesting code
    
    Remove helper functions for database updating. INSERT OR REPLACE is now
    used to let the database decide if it's a new entry or an update. This
    simplifys harvesting code

 po/POTFILES.in                                     |    1 -
 src/plugins/media-export/Makefile.am               |    1 -
 .../rygel-media-export-file-queue-entry.vala       |   29 ----------------
 .../media-export/rygel-media-export-harvester.vala |   35 ++++++++-----------
 .../rygel-media-export-media-cache.vala            |   31 +-----------------
 5 files changed, 16 insertions(+), 81 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5441ae1..7f4f304 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,7 +36,6 @@ src/plugins/media-export/rygel-media-export-media-cache.vala
 src/plugins/media-export/rygel-media-export-dbus-service.vala
 src/plugins/media-export/rygel-media-export-dummy-container.vala
 src/plugins/media-export/rygel-media-export-dynamic-container.vala
-src/plugins/media-export/rygel-media-export-file-queue-entry.vala
 src/plugins/media-export/rygel-media-export-harvester.vala
 src/plugins/media-export/rygel-media-export-item.vala
 src/plugins/media-export/rygel-media-export-null-container.vala
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 9f77f06..3374c96 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -33,7 +33,6 @@ librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \
 				   rygel-media-export-dbus-service.vala \
 				   rygel-media-export-recursive-file-monitor.vala \
 				   rygel-media-export-harvester.vala \
-				   rygel-media-export-file-queue-entry.vala \
 				   rygel-media-export-item.vala \
 				   rygel-media-export-writable-container.vala \
 				   rygel-media-export-object-factory.vala
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 4aca51c..0e51741 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -25,7 +25,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
     private MetadataExtractor extractor;
     private MediaCache media_db;
     private GLib.Queue<MediaContainer> containers;
-    private GLib.Queue<FileQueueEntry?> files;
+    private Gee.Queue<File> files;
     private File origin;
     private MediaContainer parent;
     private RecursiveFileMonitor monitor;
@@ -46,7 +46,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
         this.media_db = media_db;
         this.extractor.extraction_done.connect (on_extracted_cb);
         this.extractor.error.connect (on_extractor_error_cb);
-        this.files = new GLib.Queue<FileQueueEntry> ();
+        this.files = new LinkedList<File> ();
         this.containers = new GLib.Queue<MediaContainer> ();
         this.origin = null;
         this.monitor = monitor;
@@ -64,7 +64,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
                                         FILE_ATTRIBUTE_TIME_MODIFIED);
 
                 if (mtime > timestamp) {
-                    this.files.push_tail (new FileQueueEntry (file, true));
+                    this.files.offer (file);
 
                     return true;
                 } else {
@@ -72,14 +72,13 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
                     var size = info.get_size ();
                     var item = media_db.get_item (id);
                     if (item.size != size) {
-                        this.files.push_tail (new FileQueueEntry (file,
-                                                                  true));
+                        this.files.offer (file);
 
                         return true;
                     }
                 }
             } else {
-                this.files.push_tail (new FileQueueEntry (file, false));
+                this.files.offer (file);
 
                 return true;
             }
@@ -179,8 +178,8 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
             return false;
         }
 
-        if (this.files.get_length () > 0) {
-            var candidate = this.files.peek_head ().file;
+        if (this.files.size > 0) {
+            var candidate = this.files.peek ();
             this.extractor.extract (candidate);
         } else if (this.containers.get_length () > 0) {
             var container = this.containers.peek_head () as DummyContainer;
@@ -263,13 +262,13 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
             harvested (this.origin);
         }
 
-        var entry = this.files.peek_head ();
+        var entry = this.files.peek ();
         if (entry == null) {
             // this event may be triggered by another instance
             // just ignore it
            return;
         }
-        if (file == entry.file) {
+        if (file == entry) {
             var item = MediaExportItem.create_from_taglist (
                                                this.containers.peek_head (),
                                                file,
@@ -277,31 +276,27 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
             if (item != null) {
                 item.parent_ref = this.containers.peek_head ();
                 try {
-                    if (entry.update) {
-                        this.media_db.update_object (item);
-                    } else {
-                        this.media_db.save_item (item);
-                    }
+                    this.media_db.save_item (item);
                 } catch (Error error) {
                     // Ignore it for now
                 }
             }
 
-            this.files.pop_head ();
+            this.files.poll ();
             this.do_update ();
         }
     }
 
     private void on_extractor_error_cb (File file, Error error) {
-        var entry = this.files.peek_head ();
+        var entry = this.files.peek ();
         if (entry == null) {
             // this event may be triggered by another instance
             // just ignore it
             return;
         }
 
-        if (file == entry.file) {
-            this.files.pop_head ();
+        if (file == entry) {
+            this.files.poll ();
             this.do_update ();
         }
     }
@@ -312,7 +307,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
      * Reschedule the iteration and extraction
      */
     private void do_update () {
-        if (this.files.get_length () == 0 &&
+        if (this.files.size == 0 &&
             this.containers.get_length () != 0) {
             this.containers.peek_head ().updated ();
             this.containers.pop_head ();
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 2adffee..e1062a1 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -121,12 +121,9 @@ public class Rygel.MediaExport.MediaCache : Object {
          "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
 
     private const string INSERT_OBJECT_STRING =
-    "INSERT INTO Object (upnp_id, title, type_fk, parent, timestamp, uri) " +
+    "INSERT OR REPLACE INTO Object (upnp_id, title, type_fk, parent, timestamp, uri) " +
         "VALUES (?,?,?,?,?,?)";
 
-    private const string UPDATE_OBJECT_STRING =
-    "UPDATE Object SET title = ?, timestamp = ?, uri = ? WHERE upnp_id = ?";
-
     private const string DELETE_BY_ID_STRING =
     "DELETE FROM Object WHERE upnp_id IN " +
         "(SELECT descendant FROM closure WHERE ancestor = ?)";
@@ -235,24 +232,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         }
     }
 
-    public void update_object (MediaObject object) throws Error {
-        try {
-            db.begin ();
-            if (object is MediaItem) {
-                save_metadata (object as Rygel.MediaItem);
-            }
-            update_object_internal (object);
-            db.commit ();
-        } catch (Error error) {
-            warning (_("Failed to add item with ID %s: %s"),
-                     object.id,
-                     error.message);
-            db.rollback ();
-
-            throw error;
-        }
-    }
-
     public MediaObject? get_object (string object_id) throws DatabaseError {
         GLib.Value[] values = { object_id };
         MediaObject parent = null;
@@ -512,14 +491,6 @@ public class Rygel.MediaExport.MediaCache : Object {
         }
     }
 
-    private void update_object_internal (MediaObject object) throws Error {
-        GLib.Value[] values = { object.title,
-                                (int64) object.modified,
-                                object.id,
-                                object.uris.size == 0 ? null : object.uris[0]};
-        this.db.exec (UPDATE_OBJECT_STRING, values);
-    }
-
     private void save_metadata (Rygel.MediaItem item) throws Error {
         GLib.Value[] values = { item.size,
                                 item.mime_type,



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