[filescanner] Reduce number of queries during scan

Instead of SELECT'ing timestamp and then UPDATE'ing with a ping if file is
unchanged, skip the SELECT and just do a conditional UPDATE.
This commit is contained in:
ejurgensen 2017-10-01 00:45:01 +02:00
parent fe731c0993
commit fa2b4b810f

View File

@ -447,27 +447,25 @@ process_deferred_playlists(void)
} }
static void static void
process_regular_file(char *file, struct stat *sb, int type, int flags, int dir_id) process_regular_file(const char *file, struct stat *sb, int type, int flags, int dir_id)
{ {
time_t stamp;
int id;
bool is_bulkscan = (flags & F_SCAN_BULK); bool is_bulkscan = (flags & F_SCAN_BULK);
struct media_file_info mfi; struct media_file_info mfi;
char virtual_path[PATH_MAX]; char virtual_path[PATH_MAX];
int ret; int ret;
// Do not rescan metadata if file did not change since last scan // Will return 0 if file is not in library or if file mtime is newer than library timestamp
db_file_stamp_bypath(file, &stamp, &id); // - note if mtime is 0 then we always scan the file
if (stamp && (stamp >= sb->st_mtime)) ret = db_file_ping_bypath(file, sb->st_mtime);
{ if ((sb->st_mtime != 0) && (ret != 0))
db_file_ping(id);
return; return;
}
// File is new or modified - (re)scan metadata and update file in library // File is new or modified - (re)scan metadata and update file in library
memset(&mfi, 0, sizeof(struct media_file_info)); memset(&mfi, 0, sizeof(struct media_file_info));
mfi.id = id; // Sets id=0 if file is not in the library already
mfi.id = db_file_id_bypath(file);
mfi.fname = strdup(filename_from_path(file)); mfi.fname = strdup(filename_from_path(file));
mfi.path = strdup(file); mfi.path = strdup(file);