[gnome-online-miners] facebook: Update the DB only for new and modified entries



commit c5778e49925ad5a5f3f7c71e1c76fc3fc5c10355
Author: Álvaro Peña <alvaropg gmail com>
Date:   Tue Dec 3 00:56:27 2013 +0100

    facebook: Update the DB only for new and modified entries
    
    GFBGraph 0.2.2 offers the "updated_date" provided by the Facebook
    Graph API, so we can use it to check if a photo requires a complete
    update of its properties or not.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=719729

 configure.ac             |    2 +-
 src/gom-facebook-miner.c |   28 +++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ce44fdc..384dc64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ AC_PROG_CC_C_O
 AC_HEADER_STDC
 
 GDATA_MIN_VERSION=0.13.3
-GFBGRAPH_MIN_VERSION=0.2
+GFBGRAPH_MIN_VERSION=0.2.2
 GLIB_MIN_VERSION=2.35.1
 GOA_MIN_VERSION=3.2.0
 GRILO_MIN_VERSION=0.2.6
diff --git a/src/gom-facebook-miner.c b/src/gom-facebook-miner.c
index a85738b..98b5215 100644
--- a/src/gom-facebook-miner.c
+++ b/src/gom-facebook-miner.c
@@ -40,14 +40,16 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
                                  const gchar *creator,
                                  GError **error)
 {
+  GTimeVal new_mtime;
   const gchar *photo_id;
   const gchar *photo_name;
   const gchar *photo_created_time;
+  const gchar *photo_updated_time;
   const gchar *photo_link;
   gchar *identifier;
   const gchar *class = "nmm:Photo";
   gchar *resource = NULL;
-  gboolean resource_exists;
+  gboolean resource_exists, mtime_changed;
   gchar *contact_resource;
 
   photo_id = gfbgraph_node_get_id (GFBGRAPH_NODE (photo));
@@ -78,10 +80,26 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   if (*error != NULL)
     goto out;
 
-  /* TODO: Check updated time to avoid updating the photo if has not
-   * been modified since our last run
-   */
-
+  photo_updated_time = gfbgraph_node_get_updated_time (GFBGRAPH_NODE (photo));
+  if (!g_time_val_from_iso8601 (photo_updated_time, &new_mtime))
+    g_warning ("Can't convert updated time from ISO 8601 (%s) to a GTimeVal struct",
+               photo_updated_time);
+  else
+    {
+      mtime_changed = gom_tracker_update_mtime (job->connection, new_mtime.tv_sec,
+                                                resource_exists, identifier, resource,
+                                                job->cancellable, error);
+      if (*error != NULL)
+        goto out;
+
+      /* avoid updating the DB if the entry already exists and has not
+       * been modified since our last run.
+       */
+      if (!mtime_changed)
+        goto out;
+  }
+
+  /* the resource changed - just set all the properties again */
   gom_tracker_sparql_connection_insert_or_replace_triple
     (job->connection,
      job->cancellable, error,


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