Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/f-spot/ChangeLog,v
retrieving revision 1.1132
diff -u -r1.1132 ChangeLog
--- ChangeLog	21 Nov 2005 09:03:01 -0000	1.1132
+++ ChangeLog	21 Nov 2005 22:07:52 -0000
@@ -1,3 +1,11 @@
+2005-11-21  Gabriel Burt  <gabriel.burt@gmail.com>
+
+	* src/MainWindow.cs: Wrap attaching and unattaching tags
+	to photos in transactions for big speedup.
+	
+	* src/Db.cs: add methods for starting, committing, and
+	rolling back transactions.
+
 2005-11-21  Larry Ewing  <lewing@novell.com>
 
 	* libfspot/f-screen-utils.cs: remove unused param.
Index: src/Db.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/Db.cs,v
retrieving revision 1.8
diff -u -r1.8 Db.cs
--- src/Db.cs	11 Nov 2005 02:23:15 -0000	1.8
+++ src/Db.cs	21 Nov 2005 22:07:52 -0000
@@ -137,6 +137,30 @@
 			command.Dispose ();
 		}
 	}
+	
+	public void BeginTransaction () {
+		SqliteCommand command = new SqliteCommand ();
+		command.Connection = sqlite_connection;
+		command.CommandText = "BEGIN TRANSACTION";
+		command.ExecuteScalar ();
+		command.Dispose ();
+	}
+	
+	public void CommitTransaction () {
+		SqliteCommand command = new SqliteCommand ();
+		command.Connection = sqlite_connection;
+		command.CommandText = "COMMIT TRANSACTION";
+		command.ExecuteScalar ();
+		command.Dispose ();
+	}
+	
+	public void RollbackTransaction () {
+		SqliteCommand command = new SqliteCommand ();
+		command.Connection = sqlite_connection;
+		command.CommandText = "ROLLBACK";
+		command.ExecuteScalar ();
+		command.Dispose ();
+	}
 
 	SqliteConnection sqlite_connection;
 
Index: src/MainWindow.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/MainWindow.cs,v
retrieving revision 1.234
diff -u -r1.234 MainWindow.cs
--- src/MainWindow.cs	16 Nov 2005 00:39:20 -0000	1.234
+++ src/MainWindow.cs	21 Nov 2005 22:07:58 -0000
@@ -685,13 +685,16 @@
 
 		switch (args.Info) {
 		case (uint)TargetType.PhotoList:
+			db.BeginTransaction ();
 			foreach (int num in SelectedIds ()) {
 				AddTagExtended (num, tags);
 			}
+			db.CommitTransaction ();
 			break;
 		case (uint)TargetType.UriList:
 			UriList list = new UriList (args.SelectionData);
 			
+			db.BeginTransaction ();
 			foreach (string path in list.ToLocalPaths ()) {
 				Photo photo = db.Photos.GetByPath (path);
 				
@@ -702,6 +705,7 @@
 				// FIXME this should really follow the AddTagsExtended path too
 				photo.AddTag (tags);
 			}
+			db.CommitTransaction ();
 			InvalidateViews ();
 			break;
 		case (uint)TargetType.TagList:
@@ -1073,9 +1077,11 @@
 
 	public void HandleAttachTagMenuSelected (Tag t) 
 	{
+		db.BeginTransaction ();
 		foreach (int num in SelectedIds ()) {
 			AddTagExtended (num, new Tag [] {t});
 		}
+		db.CommitTransaction ();
 
 		UpdateTagEntryFromSelection ();
 	}
@@ -1087,10 +1093,12 @@
 
 	public void HandleRemoveTagMenuSelected (Tag t)
 	{
+		db.BeginTransaction ();
 		foreach (int num in SelectedIds ()) {
 			query.Photos [num].RemoveTag (t);
 			query.Commit (num);
 		}
+		db.CommitTransaction ();
 
 		UpdateTagEntryFromSelection ();
 	}
@@ -1445,19 +1453,23 @@
 
 	void AttachTags (Tag [] tags, int [] ids) 
 	{
+		db.BeginTransaction ();
 		foreach (int num in ids) {
 			AddTagExtended (num, tags);
 		}
+		db.CommitTransaction ();
 	}
 
 	public void HandleRemoveTagCommand (object obj, EventArgs args)
 	{
 		Tag [] tags = this.tag_selection_widget.TagHighlight ();
 
+		db.BeginTransaction ();
 		foreach (int num in SelectedIds ()) {
 			query.Photos [num].RemoveTag (tags);
 			query.Commit (num);
 		}
+		db.CommitTransaction ();
 
 		UpdateTagEntryFromSelection ();
 	}
@@ -1512,11 +1524,13 @@
 		// Remove the defunct tags from all the photos and
 		// replace them with the new tag.
 		Photo [] photos = db.Photos.Query (tags);
+		db.BeginTransaction ();
 		foreach (Photo p in photos) {
 			p.RemoveTag (removetags);
 			p.AddTag (tags [0]);
 			db.Photos.Commit (p);
 		}
+		db.CommitTransaction ();
 
 		// Remove the defunct tags from the tag list.
 		db.Photos.Remove (removetags);
@@ -2285,6 +2299,7 @@
 			       default_category = selection [0].Category;
 	       }
 
+		db.BeginTransaction ();
 	       for (int i = 0; i < tagnames.Length; i ++) {
 		       if (tagnames [i].Length == 0)
 			       continue;
@@ -2318,6 +2334,7 @@
 			       }
 		       }
 	       }
+		db.CommitTransaction ();
 
 	       UpdateTagEntryFromSelection ();
 	       if (view_mode == ModeType.IconView) {
