[db] Make I_FNAME index case insensitive and search fname using COLLATE NOCASE

Also some cleaning up
This commit is contained in:
ejurgensen 2017-10-14 20:50:58 +02:00
parent 88a565ea2c
commit 00b7b97382
4 changed files with 5 additions and 32 deletions

View File

@ -3008,21 +3008,6 @@ db_pl_add(struct playlist_info *pli, int *id)
#undef QADD_TMPL #undef QADD_TMPL
} }
int
db_pl_add_item_byfile(int plid, const char *filename)
{
#define Q_TMPL "INSERT INTO playlistitems (playlistid, filepath) SELECT %d, path FROM files WHERE fname='%q' GROUP BY fname HAVING COUNT(*)=1;"
char *query;
int ret;
query = sqlite3_mprintf(Q_TMPL, plid, filename);
ret = db_query_run(query, 1, 0);
return ((ret < 0) ? -1 : sqlite3_changes(hdl));
#undef Q_TMPL
}
int int
db_pl_add_item_bypath(int plid, const char *path) db_pl_add_item_bypath(int plid, const char *path)
{ {

View File

@ -597,9 +597,6 @@ db_pl_fetch_bytitlepath(const char *title, const char *path);
int int
db_pl_add(struct playlist_info *pli, int *id); db_pl_add(struct playlist_info *pli, int *id);
int
db_pl_add_item_byfile(int plid, const char *filename);
int int
db_pl_add_item_bypath(int plid, const char *path); db_pl_add_item_bypath(int plid, const char *path);

View File

@ -294,7 +294,7 @@ static const struct db_init_query db_init_table_queries[] =
"CREATE INDEX IF NOT EXISTS idx_rescan ON files(path, db_timestamp);" "CREATE INDEX IF NOT EXISTS idx_rescan ON files(path, db_timestamp);"
#define I_FNAME \ #define I_FNAME \
"CREATE INDEX IF NOT EXISTS idx_fname ON files(disabled, fname);" "CREATE INDEX IF NOT EXISTS idx_fname ON files(disabled, fname COLLATE NOCASE);"
#define I_SONGARTISTID \ #define I_SONGARTISTID \
"CREATE INDEX IF NOT EXISTS idx_sari ON files(songartistid);" "CREATE INDEX IF NOT EXISTS idx_sari ON files(songartistid);"

View File

@ -149,16 +149,7 @@ process_regular_file(int pl_id, char *path)
path[i] = '/'; path[i] = '/';
} }
// Fast path - only works if there are not multiple items in the lib with the ret = db_snprintf(filter, sizeof(filter), "f.fname = '%q' COLLATE NOCASE", filename_from_path(path));
// same filename
/* ret = db_pl_add_item_byfile(pl_id, filename_from_path(path));
if (ret == 1)
return 0;
DPRINTF(E_DBG, L_SCAN, "Fast path adding '%s' to playlist did not work (ret=%d), now searching\n", path, ret);
*/
ret = db_snprintf(filter, sizeof(filter), "f.fname = '%q'", filename_from_path(path)); // TODO make case insensitive?
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_SCAN, "Path in playlist is too long: '%s'\n", path); DPRINTF(E_LOG, L_SCAN, "Path in playlist is too long: '%s'\n", path);
@ -184,8 +175,6 @@ process_regular_file(int pl_id, char *path)
{ {
if (qp.results == 1) if (qp.results == 1)
{ {
DPRINTF(E_DBG, L_SCAN, "Adding '%s' to playlist %d (fast path)\n", dbpath, pl_id);
winner = strdup(dbpath); winner = strdup(dbpath);
break; break;
} }
@ -193,7 +182,7 @@ process_regular_file(int pl_id, char *path)
for (i = 0, a = NULL, b = NULL; (parent_dir(&a, path) == 0) && (parent_dir(&b, dbpath) == 0) && (strcasecmp(a, b) == 0); i++) for (i = 0, a = NULL, b = NULL; (parent_dir(&a, path) == 0) && (parent_dir(&b, dbpath) == 0) && (strcasecmp(a, b) == 0); i++)
; ;
DPRINTF(E_DBG, L_SCAN, "Comparison of '%s' and '%s' gave score %d\n", dbpath, path, i); DPRINTF(E_SPAM, L_SCAN, "Comparison of '%s' and '%s' gave score %d\n", dbpath, path, i);
if (i > score) if (i > score)
{ {
@ -216,6 +205,8 @@ process_regular_file(int pl_id, char *path)
return -1; return -1;
} }
DPRINTF(E_DBG, L_SCAN, "Adding '%s' to playlist %d (results %d)\n", dbpath, pl_id, qp.results);
db_pl_add_item_bypath(pl_id, winner); db_pl_add_item_bypath(pl_id, winner);
free(winner); free(winner);