From 8a5dd18fcc73a8df0cbc1e4fd39b7e7cb68e5703 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 12 Mar 2020 13:07:00 +0900 Subject: [PATCH] Code cleanup 1. Simplify media existence check function 2. Initialize the noti list after publish Change-Id: I08ae9955eb1b7adcfdd02c73aa22e1188a118f08 Signed-off-by: Minje Ahn --- src/common/media-svc-media.c | 9 +++------ src/common/media-svc-noti.c | 2 ++ src/common/media-svc.c | 27 ++------------------------- src/include/common/media-svc-media.h | 2 +- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c index 55c379d..7fbb832 100755 --- a/src/common/media-svc-media.c +++ b/src/common/media-svc-media.c @@ -35,7 +35,7 @@ static __thread GList *g_media_svc_scanner_query_list = NULL; static __thread GList *g_media_svc_update_list = NULL; -int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count) +int _media_svc_check_data_by_path(sqlite3 *handle, const char *path) { int ret = MS_MEDIA_ERR_NONE; sqlite3_stmt *sql_stmt = NULL; @@ -43,15 +43,12 @@ int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *co media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL"); - sql = sqlite3_mprintf("SELECT count(*) FROM %q WHERE media_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path); + sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", MEDIA_SVC_DB_TABLE_MEDIA, path); ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - - *count = sqlite3_column_int(sql_stmt, 0); - SQLITE3_FINALIZE(sql_stmt); - return MS_MEDIA_ERR_NONE; + return ret; } int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time) diff --git a/src/common/media-svc-noti.c b/src/common/media-svc-noti.c index bb75cb1..9f7172c 100755 --- a/src/common/media-svc-noti.c +++ b/src/common/media-svc-noti.c @@ -119,6 +119,8 @@ void _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info) void _media_svc_publish_noti_list(void) { g_slist_foreach(g_inserted_noti_list, __media_svc_publish_noti_by_item, NULL); + + _media_svc_initialize_noti_list(); } void _media_svc_destroy_noti_item(media_svc_noti_item *item) diff --git a/src/common/media-svc.c b/src/common/media-svc.c index 8ddf47d..8f59feb 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -140,12 +140,6 @@ int media_svc_create_table(uid_t uid) media_svc_error("user_version update fail."); goto ERROR; } - - _media_svc_destroy_table_query(); - - media_svc_debug_fleave(); - - return MS_MEDIA_ERR_NONE; ERROR: _media_svc_destroy_table_query(); @@ -156,21 +150,7 @@ ERROR: int media_svc_check_item_exist_by_path(sqlite3 *handle, const char *storage_id, const char *path) { - int ret = MS_MEDIA_ERR_NONE; - int count = -1; - - ret = _media_svc_count_record_with_path(handle, path, &count); - media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - - if (count > 0) { - media_svc_debug("item is exist in database"); - return MS_MEDIA_ERR_NONE; - } else { - media_svc_debug("item is not exist in database"); - return MS_MEDIA_ERR_DB_NO_RECORD; - } - - return MS_MEDIA_ERR_NONE; + return _media_svc_check_data_by_path(handle, path); } int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const char *path, int *modified_time) @@ -204,7 +184,6 @@ int media_svc_insert_item_end(uid_t uid) if (g_insert_with_noti) { media_svc_debug("sending noti list"); _media_svc_publish_noti_list(); - _media_svc_initialize_noti_list(); g_insert_with_noti = false; _media_svc_set_noti_from_pid(-1); } @@ -269,10 +248,8 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid); media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info); - if (g_insert_with_noti) { + if (g_insert_with_noti) _media_svc_publish_noti_list(); - _media_svc_initialize_noti_list(); - } g_media_svc_cur_data_cnt = 0; } diff --git a/src/include/common/media-svc-media.h b/src/include/common/media-svc-media.h index 171f4b7..26c8735 100755 --- a/src/include/common/media-svc-media.h +++ b/src/include/common/media-svc-media.h @@ -28,7 +28,7 @@ #include "media-svc-noti.h" #include "media-svc-util.h" -int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count); +int _media_svc_check_data_by_path(sqlite3 *handle, const char *path); int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modified_time); int _media_svc_insert_item_with_data(bool is_direct, media_svc_content_info_s *content_info, bool stack_query, uid_t uid); int _media_svc_update_item_with_data(bool is_direct, media_svc_content_info_s *content_info, uid_t uid); -- 2.7.4