[f-spot] Add URI based quick-rejection test to duplicate detect.



commit 9cad640b7bfd9d571ec13bce0a5c120215765b57
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sat Aug 7 19:59:56 2010 +0200

    Add URI based quick-rejection test to duplicate detect.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=626317

 src/PhotoStore.cs |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index 2bd1f58..1f3c71e 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -101,6 +101,17 @@ public class PhotoStore : DbStore<Photo> {
 
 	public bool HasDuplicate (IBrowsableItem item) {
 		var uri = item.DefaultVersion.Uri;
+
+		// Check if the exact given uri already exists.
+		var query = "SELECT COUNT(*) AS count FROM photo_versions WHERE base_uri = ? AND filename = ?";
+		var reader = Database.Query (new HyenaSqliteCommand (query, uri.GetBaseUri ().ToString (), uri.GetFilename ()));
+		reader.Read ();
+		int count = Convert.ToInt32 (reader ["count"]);
+		reader.Close();
+		if (count > 0)
+			return true;
+
+		// Check by MD5. Won't import if there are photos with the same ImportMD5.
 		string hash = item.DefaultVersion.ImportMD5;
 		var condition = new ConditionWrapper (String.Format ("import_md5 = \"{0}\"", hash));
 		var dupes_by_hash = Count ("photo_versions", condition);
@@ -117,7 +128,7 @@ public class PhotoStore : DbStore<Photo> {
 			DateTime? time = null;
 
 			// Look for a filename match.
-			var reader = Database.Query (new HyenaSqliteCommand ("SELECT photos.id, photos.time, pv.filename FROM photos LEFT JOIN photo_versions AS pv ON pv.photo_id = photos.id WHERE pv.filename = ?", name));
+			reader = Database.Query (new HyenaSqliteCommand ("SELECT photos.id, photos.time, pv.filename FROM photos LEFT JOIN photo_versions AS pv ON pv.photo_id = photos.id WHERE pv.filename = ?", name));
 			while (reader.Read ()) {
 				Log.DebugFormat ("Found one possible duplicate for {0}", reader["filename"].ToString ());
 				if (!time.HasValue) {
@@ -137,6 +148,7 @@ public class PhotoStore : DbStore<Photo> {
 			reader.Close ();
 		}
 
+		// No matches
 		return false;
 	}
 



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