Reduce db access 14/265514/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 21 Oct 2021 07:54:34 +0000 (16:54 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 21 Oct 2021 09:28:08 +0000 (09:28 +0000)
To improve initialization performance, this patch reduces to access to
the pkgmgr db. Before loading all applications information, AMD creates
the app property handle of the user. After this patch is applied, AMD
does not load the metadata information while calling _app_property_load().
The metadata will be inserted when a new appinfo is inserted automatically
at the initialization time.

Change-Id: I48917276ff870b2b98591780d0b13e9825cf6d67
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_app_property.c
src/lib/amd_app_property.h
src/lib/amd_appinfo.c
src/lib/amd_login_monitor.c

index 8bcc545..2445765 100644 (file)
@@ -269,6 +269,22 @@ int _app_property_insert(uid_t uid, const char *appid,
        return 0;
 }
 
+int _app_property_insert_metadata(uid_t uid, const pkgmgrinfo_appinfo_h handle)
+{
+       app_property_h app_property;
+
+       app_property = _app_property_find(uid);
+       if (app_property == NULL)
+               return -1;
+
+       if (__foreach_metadata_info(handle, app_property) != 0) {
+               _E("Failed to retrieve metadata info");
+               return -1;
+       }
+
+       return 0;
+}
+
 int _app_property_delete(uid_t uid, const char *appid)
 {
        app_property_h app_property;
@@ -524,46 +540,6 @@ static int __foreach_metadata_info(const pkgmgrinfo_appinfo_h handle,
        return 0;
 }
 
-static int __load_metadata(struct app_property_s *prop)
-{
-       pkgmgrinfo_appinfo_metadata_filter_h handle;
-       int ret;
-       GList *iter;
-       struct metadata_filter *filter;
-
-       ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
-       if (ret != PMINFO_R_OK)
-               return -1;
-
-       for (iter = metadata_filters; iter; iter = g_list_next(iter)) {
-               filter = (struct metadata_filter *)iter->data;
-               ret = pkgmgrinfo_appinfo_metadata_filter_add(handle,
-                               filter->key, filter->value);
-               if (ret != PMINFO_R_OK) {
-                       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-                       return -1;
-               }
-       }
-
-       ret = pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle,
-                       __foreach_metadata_info, prop, prop->uid);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return -1;
-       }
-
-       ret = pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle,
-                       __foreach_metadata_info, prop, GLOBAL_USER);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-               return -1;
-       }
-
-       pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
-
-       return 0;
-}
-
 static int __load_app_property(struct app_property_s *prop)
 {
        struct cb_info_s cb_info;
@@ -593,13 +569,6 @@ static int __load_app_property(struct app_property_s *prop)
                return -1;
        }
 
-       ret = __load_metadata(prop);
-       if (ret < 0) {
-               _E("Failed to retrieve metadata info uid(%d) - ret(%d)",
-                               prop->uid, ret);
-               return -1;
-       }
-
        return 0;
 }
 
index 5c672e6..a10108d 100644 (file)
@@ -52,6 +52,8 @@ app_property_h _app_property_find(uid_t uid);
 int _app_property_insert(uid_t uid, const char *appid,
                const pkgmgrinfo_appinfo_h handle);
 
+int _app_property_insert_metadata(uid_t uid, const pkgmgrinfo_appinfo_h handle);
+
 int _app_property_delete(uid_t uid, const char *appid);
 
 int _app_property_load(uid_t uid);
index f8852b8..42d8abd 100644 (file)
@@ -56,6 +56,7 @@ typedef struct _appinfo_vft {
 struct user_appinfo {
        uid_t uid;
        GHashTable *tbl; /* key is appid, value is struct appinfo */
+       bool initializing;
 };
 
 struct app_event_info {
@@ -1053,7 +1054,10 @@ static int __appinfo_insert_handler (const pkgmgrinfo_appinfo_h handle,
                c->val[AIT_PKGTYPE], c->val[AIT_APPTYPE]);
 
        g_hash_table_insert(info->tbl, c->val[AIT_NAME], c);
-       _app_property_insert(info->uid, c->val[AIT_NAME], handle);
+       if (info->initializing)
+               _app_property_insert_metadata(info->uid, handle);
+       else
+               _app_property_insert(info->uid, c->val[AIT_NAME], handle);
        _noti_send(AMD_NOTI_MSG_APPINFO_INSERT, info->uid, 0, handle, NULL);
 
        return 0;
@@ -1186,12 +1190,15 @@ static struct user_appinfo *__add_user_appinfo(uid_t uid)
 
        g_hash_table_insert(user_tbl, GINT_TO_POINTER(uid), info);
 
+       info->initializing = true;
        option = PMINFO_APPINFO_GET_CATEGORY |
                PMINFO_APPINFO_GET_APP_CONTROL |
                PMINFO_APPINFO_GET_SPLASH_SCREEN |
-               PMINFO_APPINFO_GET_RES_CONTROL;
+               PMINFO_APPINFO_GET_RES_CONTROL |
+               PMINFO_APPINFO_GET_METADATA;
        r = pkgmgrinfo_appinfo_get_usr_installed_list_full(
                        __appinfo_insert_handler, uid, option, info);
+       info->initializing = false;
        if (r != PMINFO_R_OK) {
                __remove_user_appinfo(uid);
                return NULL;
@@ -1878,7 +1885,8 @@ static void __reload_appinfo(gpointer key, gpointer value, gpointer user_data)
        option = PMINFO_APPINFO_GET_CATEGORY |
                PMINFO_APPINFO_GET_APP_CONTROL |
                PMINFO_APPINFO_GET_SPLASH_SCREEN |
-               PMINFO_APPINFO_GET_RES_CONTROL;
+               PMINFO_APPINFO_GET_RES_CONTROL |
+               PMINFO_APPINFO_GET_METADATA;
        r = pkgmgrinfo_appinfo_get_usr_installed_list_full(
                        __appinfo_insert_handler, info->uid, option, info);
        if (r != PMINFO_R_OK) {
index 2812d5b..22d71ac 100644 (file)
@@ -87,12 +87,12 @@ static login_handler login_table[] = {
        {
                .state = UID_STATE_OPENING | UID_STATE_ONLINE |
                        UID_STATE_ACTIVE,
-               .login = _appinfo_load
+               .login = _app_property_load
        },
        {
                .state = UID_STATE_OPENING | UID_STATE_ONLINE |
                        UID_STATE_ACTIVE,
-               .login = _app_property_load
+               .login = _appinfo_load
        },
        {
                .state = UID_STATE_OPENING | UID_STATE_ONLINE |