Folder related functions cleanup
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc.c
index 4afa99d..55fb6ce 100755 (executable)
 #include "media-svc-noti.h"
 #include "media-svc-storage.h"
 
-static __thread int g_media_svc_data_cnt = 0;
+//static __thread int g_media_svc_data_cnt = 0;
 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_REQUEST_MAX 300
+#define BATCH_ITEM_COUNT_MAX 100
 
 int media_svc_get_user_version(sqlite3 *handle, int *user_version)
 {
@@ -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)
@@ -178,11 +158,8 @@ int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const c
        return _media_svc_get_modified_time(handle, path, modified_time);
 }
 
-int media_svc_insert_item_begin(int data_cnt, bool with_noti, int from_pid)
+int media_svc_insert_item_begin(bool with_noti, int from_pid)
 {
-       media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
-
-       g_media_svc_data_cnt = data_cnt;
        g_media_svc_cur_data_cnt = 0;
 
        /* Prepare for making noti item list */
@@ -207,13 +184,11 @@ 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);
                }
        }
 
-       g_media_svc_data_cnt = 0;
        g_media_svc_cur_data_cnt = 0;
 
        return ret;
@@ -248,7 +223,8 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
                ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
                break;
        default:
-               media_svc_debug("Do nothing[%d]", content_info.media_type);
+               /* The 'TITLE' should always be filled in */
+               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
                break;
        }
 
@@ -267,14 +243,13 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
        if (g_insert_with_noti)
                _media_svc_insert_item_to_noti_list(&content_info);
 
-       if (++g_media_svc_cur_data_cnt == g_media_svc_data_cnt) {
+       /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+       if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
                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;
        }
@@ -312,7 +287,8 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
                ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
                break;
        default:
-               media_svc_debug("Do nothing[%d]", content_info.media_type);
+               /* The 'TITLE' should always be filled in */
+               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
                break;
        }
 
@@ -428,7 +404,8 @@ int media_svc_set_item_validity(const char *path, int validity, uid_t uid)
        ret = _media_svc_update_item_validity(path, validity, true, uid);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
-       if (++g_media_svc_cur_data_cnt == g_media_svc_data_cnt) {
+       /* To avoid over-occupying memory, update per BATCH_ITEM_COUNT_MAX. */
+       if (++g_media_svc_cur_data_cnt == BATCH_ITEM_COUNT_MAX) {
                ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
                media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
@@ -530,7 +507,8 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
                ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
                break;
        default:
-               media_svc_debug("Do nothing[%d]", content_info.media_type);
+               /* The 'TITLE' should always be filled in */
+               content_info.media_meta.title = _media_svc_get_title_by_path(content_info.path);
                break;
        }
 
@@ -750,21 +728,7 @@ int media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const
 
 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-       int count = -1;
-
-       ret = _media_svc_count_folder_with_path(handle, storage_id, folder_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_folder_by_path(handle, storage_id, folder_path);
 }
 
 int media_svc_append_query(const char *query, uid_t uid)