From 4a929bd8e2bc6a8ab08d49335c7bac12856dc46f Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 19 Sep 2017 16:58:28 -0700 Subject: [PATCH] Optimize scanning using directory name hint As discussed in issue #5440, directory scans are slow when compressed files must be checked against multiple databases. This commit adds support to hint to the scanner that a particular database should be used so that only a single scan is required. If the directory name being scanned matches the database name then that single database is selected. --- tasks/task_database.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tasks/task_database.c b/tasks/task_database.c index 026a8d5849..0919499293 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -1115,6 +1115,35 @@ static void task_database_handler(retro_task_t *task) dbstate->list = dir_list_new_special( db->content_database_path, DIR_LIST_DATABASES, NULL); + + /* If the scan path matches a database path exactly then + * save time by only processing that database. */ + if (dbstate->list && db->is_directory) + { + char *dirname = find_last_slash(db->fullpath) + 1; + + for (size_t i = 0; i < dbstate->list->size; i++) + { + char *dbpath = strdup(dbstate->list->elems[i].data); + path_remove_extension(dbpath); + char *dbname = find_last_slash(dbpath) + 1; + + if (strcasecmp(dbname, dirname) == 0) + { + free(dbpath); + struct string_list *single_list = string_list_new(); + string_list_append(single_list, dbstate->list->elems[i].data, + dbstate->list->elems[i].attr); + dir_list_free(dbstate->list); + dbstate->list = single_list; + break; + } + else + { + free(dbpath); + } + } + } } dbinfo->status = DATABASE_STATUS_ITERATE_START; break;