From 7632bdc618552f4beabd0970d786ffaf9c59acdc Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 19 Feb 2020 10:26:21 +0900 Subject: [PATCH] Use transaction for scanner requests To improve scanning performance, use transaction for scanner requests Change-Id: I5e129af02df886f972a1cca15d28e33603105537 Signed-off-by: Minje Ahn --- src/common/media-svc-db-utils.c | 20 ++++++++++++++++++++ src/common/media-svc.c | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c index 3542fe7..d7696e2 100755 --- a/src/common/media-svc-db-utils.c +++ b/src/common/media-svc-db-utils.c @@ -983,7 +983,9 @@ int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid) int idx = 0; int length = g_list_length(*query_list); char *sql = NULL; + char *zErrMsg = NULL; sqlite3 *handle = NULL; + bool with_transaction = true; media_svc_debug("query list length[%d]", length); if (length == 0) @@ -992,6 +994,13 @@ int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid) ret = media_db_connect(&handle, uid, true); media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "DB connection failed"); + ret = sqlite3_exec(handle, "BEGIN;", NULL, NULL, &zErrMsg); + if (SQLITE_OK != ret) { + media_svc_sec_error("Transaction failed[%s]. Try an individual insert.", zErrMsg); + SQLITE3_SAFE_FREE(zErrMsg); + with_transaction = false; + } + for (idx = 0; idx < length; idx++) { sql = (char *)g_list_nth_data(*query_list, idx); if (STRING_VALID(sql)) { @@ -1003,6 +1012,17 @@ int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid) } } + if (with_transaction) { + ret = sqlite3_exec(handle, "COMMIT;", NULL, NULL, &zErrMsg); + if (SQLITE_OK != ret) { + media_svc_sec_error("Commit failed[%s]", zErrMsg); + SQLITE3_SAFE_FREE(zErrMsg); + media_db_disconnect(handle); + _media_svc_sql_query_release(query_list); + return MS_MEDIA_ERR_DB_INTERNAL; + } + } + media_db_disconnect(handle); ZERO_LEN: diff --git a/src/common/media-svc.c b/src/common/media-svc.c index 344ae65..7356232 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -38,7 +38,7 @@ static __thread int g_media_svc_cur_data_cnt = 0; /* Flag for items to be published by notification */ static __thread bool g_insert_with_noti = false; -#define BATCH_ITEM_COUNT_MAX 30 +#define BATCH_ITEM_COUNT_MAX 100 int media_svc_get_user_version(sqlite3 *handle, int *user_version) { -- 2.7.4