From 566e3263a8ad4953ea7a6b06e68cbe1939fddd02 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Thu, 1 Sep 2011 01:18:28 +0000 Subject: [PATCH] * Cache the last directory hit when filling playlists, to avoid unnecessary database queries with some libraries. --- playlist.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/playlist.c b/playlist.c index 1d7f486..8dd3821 100644 --- a/playlist.c +++ b/playlist.c @@ -89,7 +89,7 @@ fill_playlists() { int rows, i, found, len; char **result; - char *plpath, *plname, *fname; + char *plpath, *plname, *fname, *last_dir; char class[] = "playlistContainer"; struct song_metadata plist; struct stat file; @@ -111,6 +111,7 @@ fill_playlists() plID = strtoll(result[i], NULL, 10); plname = result[++i]; plpath = result[++i]; + last_dir = NULL; strncpy(type, strrchr(plpath, '.')+1, 4); @@ -141,6 +142,18 @@ fill_playlists() freetags(&plist); continue; } + if( last_dir ) + { + fname = basename(plist.path); + detailID = sql_get_int_field(db, "SELECT ID from DETAILS where PATH = '%s/%s'", last_dir, fname); + if( detailID <= 0 ) + { + sqlite3_free(last_dir); + last_dir = NULL; + } + else + goto found; + } fname = plist.path; DPRINTF(E_DEBUG, L_SCANNER, "%d: checking database for %s\n", plist.track, plist.path); @@ -164,6 +177,7 @@ retry: detailID = sql_get_int_field(db, "SELECT ID from DETAILS where PATH like '%%%q'", fname); if( detailID > 0 ) { +found: DPRINTF(E_DEBUG, L_SCANNER, "+ %s found in db\n", fname); sql_exec(db, "INSERT into OBJECTS" " (OBJECT_ID, PARENT_ID, CLASS, DETAIL_ID, NAME, REF_ID) " @@ -173,6 +187,13 @@ retry: MUSIC_PLIST_ID, plID, plist.track, MUSIC_PLIST_ID, plID, detailID); + if( !last_dir ) + { + last_dir = sql_get_text_field(db, "SELECT PATH from DETAILS where ID = %lld", detailID); + fname = strrchr(last_dir, '/'); + if( fname ) + *fname = '\0'; + } found++; } else @@ -191,6 +212,11 @@ retry: } freetags(&plist); } + if( last_dir ) + { + sqlite3_free(last_dir); + last_dir = NULL; + } sql_exec(db, "UPDATE PLAYLISTS set FOUND = %d where ID = %lld", found, plID); } sqlite3_free_table(result);