From a226e8c50acc4421970dd8611947d4cde44a1c67 Mon Sep 17 00:00:00 2001
From: Nikias Bassen <nikias@gmx.li>
Date: Fri, 28 Aug 2009 13:39:16 +0200
Subject: [PATCH 14/14] Speed up artwork writing by not resolving the whole path again and again.

---
 src/ithumb-writer.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/ithumb-writer.c b/src/ithumb-writer.c
index 610777d..d55f4f0 100644
--- a/src/ithumb-writer.c
+++ b/src/ithumb-writer.c
@@ -661,13 +661,7 @@ ipod_image_get_ithmb_filename (const char *ithmb_dir, gint format_id, gint index
 	g_return_val_if_fail (ithmb_dir, NULL);
 
 	buf = g_strdup_printf ("F%d_%d.ithmb", format_id, index);
-	filename = itdb_get_path (ithmb_dir, buf);
-
-	/* itdb_get_path() only returns existing paths */
-	if (!filename)
-	{
-	    filename = g_build_filename (ithmb_dir, buf, NULL);
-	}
+	filename = g_build_filename (ithmb_dir, buf, NULL);
 /*	printf ("%s %s\n", buf, filename);*/
 
 	g_free (buf);
@@ -1356,6 +1350,7 @@ ithmb_rearrange_existing_thumbnails (const gchar *thumbs_dir,
     gint i;
     gchar *filename;
 
+    g_return_val_if_fail (thumbs_dir, FALSE);
     g_return_val_if_fail (db, FALSE);
     g_return_val_if_fail (info, FALSE);
     g_return_val_if_fail (db_get_device(db), FALSE);
@@ -1391,14 +1386,13 @@ ithmb_rearrange_existing_thumbnails (const gchar *thumbs_dir,
                             item = itdb_thumb_ipod_get_item_by_type (thumb,
                                                                      info);
                             if (item) {
-				filename = itdb_thumb_ipod_get_filename (
-				        db_get_device(db),
-				        item);
-				if (filename)
-				{
+				filename = g_build_filename(thumbs_dir, item->filename+1, NULL);
+				if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
 					thumbs = g_hash_table_lookup (filenamehash, filename);
 					thumbs = g_list_append (thumbs, item);
 					g_hash_table_insert (filenamehash, filename, thumbs);
+				} else {
+					g_free(filename);
 				}
                             }
                         }
@@ -1417,13 +1411,13 @@ ithmb_rearrange_existing_thumbnails (const gchar *thumbs_dir,
                     item = itdb_thumb_ipod_get_item_by_type (thumb, info);
                     if (item) 
                     {
-			filename = itdb_thumb_ipod_get_filename (
-			        db_get_device (db), item);
-			if (filename)
-			{
+			filename = g_build_filename(thumbs_dir, item->filename+1, NULL);
+			if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
 				thumbs = g_hash_table_lookup (filenamehash, filename);
 				thumbs = g_list_append (thumbs, item);
 				g_hash_table_insert (filenamehash, filename, thumbs);
+			} else {
+				g_free(filename);
 			}
                     } 
                 }
-- 
1.6.4.4

