Revision: 2037
http://gtkpod.svn.sourceforge.net/gtkpod/?rev=2037&view=rev
Author: jcsjcs
Date: 2008-07-06 05:13:44 -0700 (Sun, 06 Jul 2008)
Log Message:
-----------
* src/syncdir.c: hash filenames of tracks to reduce overhead
when syncing parts of large repositories. Thanks to Clarke
Brunsdon for the initial patch.
* src/file.c: also update mtime of updated tracks.
Modified Paths:
--------------
gtkpod/trunk/ChangeLog
gtkpod/trunk/src/file.c
gtkpod/trunk/src/syncdir.c
Modified: gtkpod/trunk/ChangeLog
===================================================================
--- gtkpod/trunk/ChangeLog 2008-07-06 09:42:07 UTC (rev 2036)
+++ gtkpod/trunk/ChangeLog 2008-07-06 12:13:44 UTC (rev 2037)
@@ -1,3 +1,12 @@
+2008-07-06 Jorg Schuler <jcsjcs at users.sourceforge.net>
+
+ * src/syncdir.c: hash filenames of tracks to reduce overhead
+ when syncing parts of large repositories. Thanks to Clarke
+ Brunsdon for the initial patch.
+
+ * src/file.c: also update mtime of updated tracks.
+
+
2008-07-05 Jorg Schuler <jcsjcs at users.sourceforge.net>
* src/display_coverart.c:
@@ -4,6 +13,7 @@
Normalized indentation (original editor was mis-configured).
+
2008-07-05 Jorg Schuler <jcsjcs at users.sourceforge.net>
* src/misc_conversion.c (ST_to_T)
Modified: gtkpod/trunk/src/file.c
===================================================================
--- gtkpod/trunk/src/file.c 2008-07-06 09:42:07 UTC (rev 2036)
+++ gtkpod/trunk/src/file.c 2008-07-06 12:13:44 UTC (rev 2037)
@@ -825,10 +825,10 @@
case T_SORT_TVSHOW:
case T_YEAR:
case T_TRACK_NR:
- case T_SIZE:
case T_TRACKLEN:
case T_STARTTIME:
case T_STOPTIME:
+ case T_SIZE:
case T_BITRATE:
case T_SAMPLERATE:
case T_BPM:
@@ -914,6 +914,12 @@
to->gapless_track_flag = from->gapless_track_flag;
}
+ if (eto->mtime != efrom->mtime)
+ {
+ changed = TRUE;
+ eto->mtime = efrom->mtime;
+ }
+
return changed;
}
@@ -1813,7 +1819,6 @@
trackpath = get_file_name_from_source (track, SOURCE_PREFER_LOCAL);
-
if (!(oetr->pc_path_locale && *oetr->pc_path_locale))
{ /* no path available */
if (trackpath)
Modified: gtkpod/trunk/src/syncdir.c
===================================================================
--- gtkpod/trunk/src/syncdir.c 2008-07-06 09:42:07 UTC (rev 2036)
+++ gtkpod/trunk/src/syncdir.c 2008-07-06 12:13:44 UTC (rev 2037)
@@ -1,4 +1,4 @@
-/* Time-stamp: <2007-06-17 23:01:18 jcs>
+/* Time-stamp: <2008-07-06 10:38:05 jcs>
|
| Copyright (C) 2002-2005 Jorg Schuler <jcsjcs at users sourceforge net>
| Part of the gtkpod project.
@@ -48,9 +48,18 @@
{
Playlist *playlist;
GList **tracks_updated;
+ GHashTable *filepath_hash;
};
+/* Used in the callback after adding a new track to
+ * to add to the filehash */
+struct added_file_data
+{
+ GHashTable *filepath_hash;
+ gchar *filepath;
+};
+
/**
* confirm_sync_dirs:
*
@@ -299,16 +308,54 @@
* again if it already exists */
static void sync_addtrackfunc (Playlist *plitem, Track *track, gpointer data)
{
+ struct added_file_data *afd = data;
+
g_return_if_fail (plitem);
g_return_if_fail (track);
- /* only add if @track isn't already a member of the current
- playlist */
+ g_return_if_fail (afd->filepath_hash);
+ g_return_if_fail (afd->filepath);
+
+ /* add the new entry to the filepath */
+ g_hash_table_insert (afd->filepath_hash, g_strdup (afd->filepath), track);
+
+ /* only add if @track isn't already a member of the current playlist */
if (!itdb_playlist_contains_track (plitem, track))
gp_playlist_add_track (plitem, track, TRUE);
}
+/* Builds a hash of all the tracks in the playlists db,
+ * hashed by the file path */
+static GHashTable *get_itdb_filepath_hash (Playlist *pl)
+{
+ GHashTable* filepath_hash;
+ iTunesDB *itdb = pl->itdb;
+
+ filepath_hash = g_hash_table_new_full (
+ g_str_hash, g_str_equal, g_free, NULL);
+
+ GList *gl;
+ for (gl=itdb->tracks; gl; gl=gl->next)
+ {
+ ExtraTrackData *etr;
+ Track *track = gl->data;
+ g_return_val_if_fail (track, NULL);
+
+ etr = track->userdata;
+ g_return_val_if_fail (etr, NULL);
+
+ /* track has filename info */
+ if (etr->pc_path_locale && *etr->pc_path_locale)
+ {
+ g_hash_table_insert (filepath_hash, g_strdup (etr->pc_path_locale),
track);
+ }
+ }
+
+ return filepath_hash;
+}
+
+
/**
* add_files:
*
@@ -319,12 +366,15 @@
{
struct add_files_data *afd = user_data;
Playlist *pl;
- gchar *dirname = key;
+ gchar *dirname;
g_return_if_fail (key);
g_return_if_fail (afd);
g_return_if_fail (afd->playlist);
g_return_if_fail (afd->tracks_updated);
+ g_return_if_fail (afd->filepath_hash);
+
+ dirname = key;
pl = afd->playlist;
if (g_file_test (dirname, G_FILE_TEST_IS_DIR))
@@ -360,21 +410,14 @@
case FILE_TYPE_MPG:
case FILE_TYPE_OGG:
case FILE_TYPE_FLAC:
- tr = gp_track_by_filename (pl->itdb, filename);
+ tr = g_hash_table_lookup (afd->filepath_hash, filename);
if (tr)
- { /* track is known -> add to playlist if not
- * already present and only update if mtime or
- * filesize is different */
+ { /* track is already present in playlist.
+ Update if date stamp is different. */
+ struct stat filestat;
ExtraTrackData *etr = tr->userdata;
- struct stat filestat;
g_return_if_fail (etr);
- if (!itdb_playlist_contains_track (pl, tr))
- {
- gp_playlist_add_track (pl, tr, TRUE);
- updated = TRUE;
- }
-
stat (filename, &filestat);
/*
printf ("%ld %ld (%s)\n, %ld %d\n",
@@ -395,10 +438,15 @@
* standard function. Duplicate adding is
* avoided by an addtrack function checking
* for duplication */
+ struct added_file_data data;
+ data.filepath = filename;
+ data.filepath_hash = afd->filepath_hash;
+
add_track_by_filename (pl->itdb, filename,
pl, FALSE,
- sync_addtrackfunc, NULL);
- tr = gp_track_by_filename (pl->itdb, filename);
+ sync_addtrackfunc, &data);
+
+ tr = g_hash_table_lookup (afd->filepath_hash, filename);
updated = TRUE;
}
break;
@@ -471,7 +519,7 @@
const gchar *key_sync_show_summary,
gboolean sync_show_summary)
{
- GHashTable *dirs_hash;
+ GHashTable *dirs_hash, *filepath_hash;
gboolean delete_tracks, is_mpl;
time_t current_time;
GList *tracks_to_delete_from_ipod = NULL;
@@ -559,10 +607,20 @@
tracks */
current_time = time (NULL);
- /* Add all files in all directories entered into dirs_hash */
+ /* craete a hash with all files in the current playlist for faster
+ * comparison with files in the directory */
+ filepath_hash = get_itdb_filepath_hash (playlist);
+
afd.playlist = playlist;
afd.tracks_updated = &tracks_updated;
+ afd.filepath_hash = filepath_hash;
+ /* Add all files in all directories present in dirs_hash */
g_hash_table_foreach (dirs_hash, add_files, &afd);
+
+ /* we won't need this hash any more */
+ g_hash_table_destroy (filepath_hash);
+ filepath_hash = NULL;
+
/* Remove updated and duplicate list so it won't pop up at a later
time */
display_updated ((void *)-1, NULL);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2