The iTunes playlist scanner improvements in 0abc9f0 resulted in too

many database lookups. This is a more efficient version.
This commit is contained in:
ejurgensen 2013-08-21 23:18:45 +02:00
parent 9d0962407a
commit 55d7224053

View File

@ -263,9 +263,11 @@ check_meta(plist_t dict)
static int static int
find_track_file(char *location) find_track_file(char *location)
{ {
int ret;
int plen; int plen;
int mfi_id; int mfi_id;
char *filename; char *entry;
char *ptr;
location = evhttp_decode_uri(location); location = evhttp_decode_uri(location);
if (!location) if (!location)
@ -281,32 +283,44 @@ find_track_file(char *location)
if (strncmp(location, "file://localhost/", plen) != 0) if (strncmp(location, "file://localhost/", plen) != 0)
return 0; return 0;
/* Windows pathspec, from iTunes Win32 */ /* Now search for the library item where the path has closest match to playlist item */
if (location[plen + 1] == ':') /* Succes is when we find an unambiguous match, or when we no longer can expand the */
plen += 2; /* the path to refine our search. */
else entry = NULL;
plen -= 1; do
/* Now look for location in the library, first using full path, gradually shorten, finally just with filename */
filename = location + plen;
while (filename && !(mfi_id = db_file_id_bypathpattern(filename)))
{ {
DPRINTF(E_SPAM, L_SCAN, "XML playlist filename is now %s\n", filename); ptr = strrchr(location, '/');
filename = strchr(filename + 1, '/'); if (entry)
} *(entry - 1) = '/';
if (ptr)
{
*ptr = '\0';
entry = ptr + 1;
}
else
entry = location;
/* Found */ DPRINTF(E_SPAM, L_SCAN, "iTunes XML playlist entry is now %s\n", entry);
if (filename && mfi_id > 0) ret = db_files_get_count_bypathpattern(entry);
} while (ptr && (ret > 1));
if (ret > 0)
{ {
DPRINTF(E_DBG, L_SCAN, "Found iTunes XML playlist entry match, id is %d, filename is %s\n", mfi_id, filename); mfi_id = db_file_id_bypathpattern(entry);
DPRINTF(E_DBG, L_SCAN, "Found iTunes XML playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
free(location); free(location);
return mfi_id; return mfi_id;
} }
else
{
DPRINTF(E_DBG, L_SCAN, "No match for iTunes XML playlist entry %s\n", entry);
free(location);
return 0;
}
/* Not found */
free(location);
return 0;
} }
static int static int