mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-05 10:48:09 -05:00
The m3u playlist scanner improvements in commit 6e9cf3a resulted in
too many database lookups. This is a more efficient version.
This commit is contained in:
parent
0abc9f04f2
commit
9d0962407a
20
src/db.c
20
src/db.c
@ -1524,6 +1524,26 @@ db_files_get_count(void)
|
|||||||
return db_get_count("SELECT COUNT(*) FROM files f WHERE f.disabled = 0;");
|
return db_get_count("SELECT COUNT(*) FROM files f WHERE f.disabled = 0;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
db_files_get_count_bypathpattern(char *path)
|
||||||
|
{
|
||||||
|
char *query;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
query = sqlite3_mprintf("SELECT COUNT(*) FROM files f WHERE f.path LIKE '%%%q';", path);
|
||||||
|
if (!query)
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_DB, "Out of memory making count query string.\n");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = db_get_count(query);
|
||||||
|
sqlite3_free(query);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
db_files_update_songalbumid(void)
|
db_files_update_songalbumid(void)
|
||||||
{
|
{
|
||||||
|
3
src/db.h
3
src/db.h
@ -319,6 +319,9 @@ db_query_fetch_string_sort(struct query_params *qp, char **string, char **sortst
|
|||||||
int
|
int
|
||||||
db_files_get_count(void);
|
db_files_get_count(void);
|
||||||
|
|
||||||
|
int
|
||||||
|
db_files_get_count_bypathpattern(char *path);
|
||||||
|
|
||||||
void
|
void
|
||||||
db_files_update_songalbumid(void);
|
db_files_update_songalbumid(void);
|
||||||
|
|
||||||
|
@ -171,17 +171,34 @@ scan_m3u_playlist(char *file, time_t mtime)
|
|||||||
buf[i] = '/';
|
buf[i] = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = buf;
|
/* Now search for the library item where the path has closest match to playlist item */
|
||||||
while (entry && !(mfi_id = db_file_id_bypathpattern(entry)))
|
/* Succes is when we find an unambiguous match, or when we no longer can expand the */
|
||||||
|
/* the path to refine our search. */
|
||||||
|
entry = NULL;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_SCAN, "Playlist entry is now %s\n", entry);
|
ptr = strrchr(buf, '/');
|
||||||
entry = strchr(entry + 1, '/');
|
if (entry)
|
||||||
}
|
*(entry - 1) = '/';
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
*ptr = '\0';
|
||||||
|
entry = ptr + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
entry = buf;
|
||||||
|
|
||||||
if (entry && mfi_id > 0)
|
DPRINTF(E_SPAM, L_SCAN, "Playlist entry is now %s\n", entry);
|
||||||
|
ret = db_files_get_count_bypathpattern(entry);
|
||||||
|
|
||||||
|
} while (ptr && (ret > 1));
|
||||||
|
|
||||||
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
|
mfi_id = db_file_id_bypathpattern(entry);
|
||||||
DPRINTF(E_DBG, L_SCAN, "Found playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
|
DPRINTF(E_DBG, L_SCAN, "Found playlist entry match, id is %d, entry is %s\n", mfi_id, entry);
|
||||||
filename = db_file_path_byid(mfi_id);
|
|
||||||
|
filename = db_file_path_byid(mfi_id);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SCAN, "Playlist entry %s matches file id %d, but file path is missing.\n", entry, mfi_id);
|
DPRINTF(E_LOG, L_SCAN, "Playlist entry %s matches file id %d, but file path is missing.\n", entry, mfi_id);
|
||||||
@ -190,7 +207,11 @@ scan_m3u_playlist(char *file, time_t mtime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
continue;
|
{
|
||||||
|
DPRINTF(E_DBG, L_SCAN, "No match for playlist entry %s\n", entry);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db_pl_add_item_bypath(pl_id, filename);
|
ret = db_pl_add_item_bypath(pl_id, filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user