Change codes for performance 39/129139/14
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 15 May 2017 06:55:11 +0000 (15:55 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 23 May 2017 02:11:39 +0000 (11:11 +0900)
- Make frequently called function as inline
- Store global uid internally
- Don't get unnecessary columns
- Remove unnecessary duplication checking routine

Change-Id: I763852d1131465efe3fdc558ae257d4429ba3ba5
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgrinfo_type.h
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_db.c
src/pkgmgrinfo_pkginfo.c
src/pkgmgrinfo_private.c
src/pkgmgrinfo_private.h

index 62c5281..e92f069 100644 (file)
@@ -93,23 +93,24 @@ typedef enum {
 } pkgmgrinfo_cert_compare_result_type_e;
 
 typedef enum {
-       PMINFO_APPINFO_GET_LABEL = 0x0001,
-       PMINFO_APPINFO_GET_ICON = 0x0002,
-       PMINFO_APPINFO_GET_CATEGORY = 0x0004,
-       PMINFO_APPINFO_GET_APP_CONTROL = 0x0008,
-       PMINFO_APPINFO_GET_DATA_CONTROL = 0x0010,
+       PMINFO_APPINFO_GET_BASICINFO = 0x0001,
+       PMINFO_APPINFO_GET_LABEL = 0x0002,
+       PMINFO_APPINFO_GET_ICON = 0x0004,
+       PMINFO_APPINFO_GET_CATEGORY = 0x0008,
+       PMINFO_APPINFO_GET_APP_CONTROL = 0x0010,
        PMINFO_APPINFO_GET_METADATA = 0x0020,
        PMINFO_APPINFO_GET_SPLASH_SCREEN = 0x0040,
        PMINFO_APPINFO_GET_ALL = 0x007F
 } pkgmgrinfo_appinfo_get_option;
 
 typedef enum {
-       PMINFO_PKGINFO_GET_LABEL = 0x0001,
-       PMINFO_PKGINFO_GET_ICON = 0x0002,
-       PMINFO_PKGINFO_GET_AUTHOR = 0x0004,
-       PMINFO_PKGINFO_GET_DESCRIPTION = 0x0008,
-       PMINFO_PKGINFO_GET_PRIVILEGE = 0x0010,
-       PMINFO_PKGINFO_GET_ALL = 0x001F
+       PMINFO_PKGINFO_GET_BASICINFO = 0x0001,
+       PMINFO_PKGINFO_GET_LABEL = 0x0002,
+       PMINFO_PKGINFO_GET_ICON = 0x0004,
+       PMINFO_PKGINFO_GET_AUTHOR = 0x0008,
+       PMINFO_PKGINFO_GET_DESCRIPTION = 0x0010,
+       PMINFO_PKGINFO_GET_PRIVILEGE = 0x0020,
+       PMINFO_PKGINFO_GET_ALL = 0x003F
 } pkgmgrinfo_pkginfo_get_option;
 
 /**
index 1529a85..6b3a1b1 100644 (file)
@@ -52,9 +52,6 @@ static const char join_app_control[] =
 static const char join_metadata[] =
        " LEFT OUTER JOIN package_app_app_metadata"
        "  ON ai.app_id=package_app_app_metadata.app_id ";
-static const char join_appinfo_for_uid[] =
-       " LEFT OUTER JOIN package_app_info_for_uid"
-       " ON ai.app_id=package_app_info_for_uid.app_id ";
 
 static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        const char *locale, uid_t uid, char **query, GList **bind_params)
@@ -130,10 +127,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
                strncat(tmp_query, join_metadata, MAX_QUERY_LEN - len - 1);
                len += strlen(join_metadata);
        }
-       if (joined & E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID) {
-               strncat(tmp_query, join_appinfo_for_uid, MAX_QUERY_LEN - len - 1);
-               len += strlen(join_appinfo_for_uid);
-       }
+
        strncat(tmp_query, buf, MAX_QUERY_LEN - len - 1);
        len += strlen(buf);
 
@@ -250,51 +244,6 @@ static int _appinfo_get_app_control(sqlite3 *db, const char *appid,
        return PMINFO_R_OK;
 }
 
-static int _appinfo_get_data_control(sqlite3 *db, const char *appid,
-               GList **datacontrol)
-{
-       static const char query_raw[] =
-               "SELECT providerid, access, type, trusted "
-               "FROM package_app_data_control WHERE app_id=%Q";
-       int ret;
-       char *query;
-       sqlite3_stmt *stmt;
-       int idx;
-       datacontrol_x *info;
-
-       query = sqlite3_mprintf(query_raw, appid);
-       if (query == NULL) {
-               LOGE("out of memory");
-               return PMINFO_R_ERROR;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       sqlite3_free(query);
-       if (ret != SQLITE_OK) {
-               LOGE("prepare failed: %s", sqlite3_errmsg(db));
-               return PMINFO_R_ERROR;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(datacontrol_x));
-               if (info == NULL) {
-                       LOGE("out of memory");
-                       sqlite3_finalize(stmt);
-                       return PMINFO_R_ERROR;
-               }
-               idx = 0;
-               _save_column_str(stmt, idx++, &info->providerid);
-               _save_column_str(stmt, idx++, &info->access);
-               _save_column_str(stmt, idx++, &info->type);
-               _save_column_str(stmt, idx++, &info->trusted);
-               *datacontrol = g_list_append(*datacontrol, info);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return PMINFO_R_OK;
-}
-
 static int _appinfo_get_metadata(sqlite3 *db, const char *appid,
                GList **metadata)
 {
@@ -427,48 +376,6 @@ static GList *__get_background_category(const char *value)
 
 }
 
-static int __get_appinfo_for_uid(sqlite3 *db, application_x *info, uid_t uid)
-{
-       static const char query_raw[] =
-               "SELECT is_splash_screen_enabled, is_disabled "
-               "FROM package_app_info_for_uid WHERE app_id=%Q AND uid=%d";
-       int ret;
-       char *query;
-       char *is_disabled = NULL;
-       sqlite3_stmt *stmt;
-
-       query = sqlite3_mprintf(query_raw, info->appid, uid);
-       if (query == NULL) {
-               LOGE("out of memory");
-               return PMINFO_R_ERROR;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       sqlite3_free(query);
-       if (ret != SQLITE_OK) {
-               LOGE("sqlite3_prepare_v2() failed: %s", sqlite3_errmsg(db));
-               return PMINFO_R_ERROR;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               if (info->splash_screen_display)
-                       free(info->splash_screen_display);
-               _save_column_str(stmt, 0, &info->splash_screen_display);
-               if (strcasecmp(info->is_disabled, "false") == 0) {
-                       _save_column_str(stmt, 1, &is_disabled);
-                       if (strcasecmp(is_disabled, "true") == 0) {
-                               free(info->is_disabled);
-                               info->is_disabled = is_disabled;
-                       } else {
-                               free(is_disabled);
-                       }
-               }
-       }
-
-       sqlite3_finalize(stmt);
-       return PMINFO_R_OK;
-}
-
 static void __free_applications(gpointer data)
 {
        pkgmgrinfo_basic_free_application((application_x *)data);
@@ -547,7 +454,10 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                GHashTable *applications)
 {
        static const char query_raw[] =
-               "SELECT DISTINCT ai.app_id, ai.app_component, ai.app_exec, "
+               "SELECT DISTINCT ai.app_id, ai.app_installed_storage, "
+               "ai.app_external_path";
+       static const char query_basic[] =
+               ", ai.app_component, ai.app_exec, "
                "ai.app_nodisplay, ai.app_type, ai.app_onboot, "
                "ai.app_multiple, ai.app_autorestart, ai.app_taskmanage, "
                "ai.app_hwacceleration, ai.app_screenreader, "
@@ -557,14 +467,15 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                "ai.app_permissiontype, ai.app_preload, ai.app_submode, "
                "ai.app_submode_mainid, ai.app_launch_mode, ai.app_ui_gadget, "
                "ai.app_support_disable, ai.app_process_pool, "
-               "ai.app_installed_storage, ai.app_background_category, "
-               "ai.app_package_type, ai.app_root_path, ai.app_api_version, "
-               "ai.app_effective_appid, ai.app_disable, "
-               "ai.app_splash_screen_display, ai.app_tep_name, "
+               "ai.app_background_category, ai.app_package_type, "
+               "ai.app_root_path, ai.app_api_version, ai.app_effective_appid, "
+               "ai.app_disable, ai.app_splash_screen_display, ai.app_tep_name, "
                "ai.app_zip_mount_file, ai.component_type, ai.package, "
-               "ai.app_external_path, ai.app_package_system, ai.app_removable, "
+               "ai.app_package_system, ai.app_removable, "
                "ai.app_package_installed_time, ai.app_support_mode, "
                "ai.app_support_ambient, ai.app_setup_appid";
+       static const char query_uid_info[] =
+               ", ui.is_disabled, ui.is_splash_screen_enabled";
        static const char query_label[] =
                ", COALESCE("
                "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
@@ -574,6 +485,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
                "(SELECT app_icon FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale='No Locale'))";
        static const char query_from_clause[] = " FROM package_app_info as ai";
+       static const char query_uid_info_clause[] =
+               " LEFT OUTER JOIN package_app_info_for_uid AS ui "
+               "ON (ai.app_id=ui.app_id AND ui.uid=?)";
        int ret = PMINFO_R_ERROR;
        int idx;
        int len = 0;
@@ -582,11 +496,13 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
        char *constraint = NULL;
        char *tmp_record = NULL;
        char query[MAX_QUERY_LEN] = { '\0' };
+       char buf[BUFSIZE] = { '\0' };
        application_x *info = NULL;
        GList *bind_params = NULL;
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
        bool is_check_storage = true;
+       const uid_t global_user_uid = GLOBAL_USER;
 
        dbpath = getUserPkgParserDBPathUID(db_uid);
        if (dbpath == NULL)
@@ -602,6 +518,13 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
 
        len = strlen(query_raw);
        snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+
+       if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+               strncat(query, query_basic, MAX_QUERY_LEN - len - 1);
+               len += strlen(query_basic);
+               strncat(query, query_uid_info, MAX_QUERY_LEN - len - 1);
+               len += strlen(query_uid_info);
+       }
        if (flag & PMINFO_APPINFO_GET_LABEL) {
                strncat(query, query_label, MAX_QUERY_LEN - len - 1);
                len += strlen(query_label);
@@ -613,6 +536,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                bind_params = g_list_append(bind_params, strdup(locale));
        }
 
+       snprintf(buf, MAX_QUERY_LEN - 1, "%d", uid);
+       bind_params = g_list_append(bind_params, strdup(buf));
+
        is_check_storage = __check_app_storage_status(filter);
 
        ret = _get_filtered_query(filter, locale, uid, &constraint, &bind_params);
@@ -623,6 +549,9 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
        strncat(query, query_from_clause, MAX_QUERY_LEN - len - 1);
        len += strlen(query_from_clause);
 
+       strncat(query, query_uid_info_clause, MAX_QUERY_LEN - len - 1);
+       len += strlen(query_uid_info_clause);
+
        if (constraint)
                strncat(query, constraint, MAX_QUERY_LEN - len - 1);
 
@@ -650,75 +579,83 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->appid);
-               if (g_hash_table_contains(applications,
-                                       (gconstpointer)info->appid)) {
-                       free(info->appid);
-                       free(info);
-                       info = NULL;
-                       continue;
-               }
-               _save_column_str(stmt, idx++, &info->component);
-               _save_column_str(stmt, idx++, &info->exec);
-               _save_column_str(stmt, idx++, &info->nodisplay);
-               _save_column_str(stmt, idx++, &info->type);
-               _save_column_str(stmt, idx++, &info->onboot);
-               _save_column_str(stmt, idx++, &info->multiple);
-               _save_column_str(stmt, idx++, &info->autorestart);
-               _save_column_str(stmt, idx++, &info->taskmanage);
-               _save_column_str(stmt, idx++, &info->hwacceleration);
-               _save_column_str(stmt, idx++, &info->screenreader);
-               _save_column_str(stmt, idx++, &info->mainapp);
-               _save_column_str(stmt, idx++, &info->recentimage);
-               _save_column_str(stmt, idx++, &info->launchcondition);
-               _save_column_str(stmt, idx++, &info->indicatordisplay);
-               _save_column_str(stmt, idx++, &info->portraitimg);
-               _save_column_str(stmt, idx++, &info->landscapeimg);
-               _save_column_str(stmt, idx++, &info->guestmode_visibility);
-               _save_column_str(stmt, idx++, &info->permission_type);
-               _save_column_str(stmt, idx++, &info->preload);
-               _save_column_str(stmt, idx++, &info->submode);
-               _save_column_str(stmt, idx++, &info->submode_mainid);
-               _save_column_str(stmt, idx++, &info->launch_mode);
-               _save_column_str(stmt, idx++, &info->ui_gadget);
-               _save_column_str(stmt, idx++, &info->support_disable);
-               _save_column_str(stmt, idx++, &info->process_pool);
                _save_column_str(stmt, idx++, &info->installed_storage);
-               _save_column_str(stmt, idx++, &bg_category_str);
-               _save_column_str(stmt, idx++, &info->package_type);
-               _save_column_str(stmt, idx++, &info->root_path);
-               _save_column_str(stmt, idx++, &info->api_version);
-               _save_column_str(stmt, idx++, &info->effective_appid);
-               _save_column_str(stmt, idx++, &info->is_disabled);
-               _save_column_str(stmt, idx++, &info->splash_screen_display);
-               _save_column_str(stmt, idx++, &info->tep_name);
-               _save_column_str(stmt, idx++, &info->zip_mount_file);
-               _save_column_str(stmt, idx++, &info->component_type);
-               _save_column_str(stmt, idx++, &info->package);
-               _save_column_str(stmt, idx++, &info->external_path);
-               _save_column_str(stmt, idx++, &info->package_system);
-               _save_column_str(stmt, idx++, &info->removable);
-               _save_column_str(stmt, idx++, &info->package_installed_time);
-               _save_column_str(stmt, idx++, &info->support_mode);
-               _save_column_str(stmt, idx++, &info->support_ambient);
-               _save_column_str(stmt, idx++, &info->setup_appid);
+               _save_column_str(stmt, idx++ , &info->external_path);
+
+               if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+                       _save_column_str(stmt, idx++, &info->component);
+                       _save_column_str(stmt, idx++, &info->exec);
+                       _save_column_str(stmt, idx++, &info->nodisplay);
+                       _save_column_str(stmt, idx++, &info->type);
+                       _save_column_str(stmt, idx++, &info->onboot);
+                       _save_column_str(stmt, idx++, &info->multiple);
+                       _save_column_str(stmt, idx++, &info->autorestart);
+                       _save_column_str(stmt, idx++, &info->taskmanage);
+                       _save_column_str(stmt, idx++, &info->hwacceleration);
+                       _save_column_str(stmt, idx++, &info->screenreader);
+                       _save_column_str(stmt, idx++, &info->mainapp);
+                       _save_column_str(stmt, idx++, &info->recentimage);
+                       _save_column_str(stmt, idx++, &info->launchcondition);
+                       _save_column_str(stmt, idx++, &info->indicatordisplay);
+                       _save_column_str(stmt, idx++, &info->portraitimg);
+                       _save_column_str(stmt, idx++, &info->landscapeimg);
+                       _save_column_str(stmt, idx++, &info->guestmode_visibility);
+                       _save_column_str(stmt, idx++, &info->permission_type);
+                       _save_column_str(stmt, idx++, &info->preload);
+                       _save_column_str(stmt, idx++, &info->submode);
+                       _save_column_str(stmt, idx++, &info->submode_mainid);
+                       _save_column_str(stmt, idx++, &info->launch_mode);
+                       _save_column_str(stmt, idx++, &info->ui_gadget);
+                       _save_column_str(stmt, idx++, &info->support_disable);
+                       _save_column_str(stmt, idx++, &info->process_pool);
+                       _save_column_str(stmt, idx++, &bg_category_str);
+                       _save_column_str(stmt, idx++, &info->package_type);
+                       _save_column_str(stmt, idx++, &info->root_path);
+                       _save_column_str(stmt, idx++, &info->api_version);
+                       _save_column_str(stmt, idx++, &info->effective_appid);
+                       _save_column_str(stmt, idx++, &info->is_disabled);
+                       _save_column_str(stmt, idx++, &info->splash_screen_display);
+                       _save_column_str(stmt, idx++, &info->tep_name);
+                       _save_column_str(stmt, idx++, &info->zip_mount_file);
+                       _save_column_str(stmt, idx++, &info->component_type);
+                       _save_column_str(stmt, idx++, &info->package);
+                       _save_column_str(stmt, idx++, &info->package_system);
+                       _save_column_str(stmt, idx++, &info->removable);
+                       _save_column_str(stmt, idx++, &info->package_installed_time);
+                       _save_column_str(stmt, idx++, &info->support_mode);
+                       _save_column_str(stmt, idx++, &info->support_ambient);
+                       _save_column_str(stmt, idx++, &info->setup_appid);
+                       info->background_category = __get_background_category(
+                                       bg_category_str);
+                       free(bg_category_str);
+               }
 
                info->for_all_users =
-                       strdup((db_uid != GLOBAL_USER) ? "false" : "true");
-
-               if (db_uid == GLOBAL_USER) {
-                       ret = __get_appinfo_for_uid(db, info, uid);
-                       if (ret != PMINFO_R_OK) {
-                               LOGI("Failed to get appinfo for given uid[%d]", (int)uid);
-                               pkgmgrinfo_basic_free_application(info);
-                               info = NULL;
-                               continue;
+                       strdup((db_uid != global_user_uid) ? "false" : "true");
+
+               if (db_uid != global_user_uid) {
+                       idx = idx + 2;
+               } else {
+                       tmp_record = NULL;
+                       _save_column_str(stmt, idx++, &tmp_record);
+                       if (tmp_record != NULL) {
+                               if (strcasecmp(info->is_disabled, "false") == 0 &&
+                                               strcasecmp(tmp_record, "false") == 0) {
+                                       free(info->is_disabled);
+                                       info->is_disabled = tmp_record;
+                               }
+                       }
+                       tmp_record = NULL;
+                       _save_column_str(stmt, idx++, &tmp_record);
+                       if (tmp_record != NULL) {
+                               if (strcasecmp(info->splash_screen_display, "false") == 0 &&
+                                               strcasecmp(tmp_record, "false") == 0) {
+                                       free(info->splash_screen_display);
+                                       info->splash_screen_display = tmp_record;
+                               }
                        }
                }
 
-               info->background_category = __get_background_category(
-                               bg_category_str);
-               free(bg_category_str);
-
                if (flag & PMINFO_APPINFO_GET_LABEL) {
                        tmp_record = NULL;
                        _save_column_str(stmt, idx++, &tmp_record);
@@ -753,14 +690,6 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                        }
                }
 
-               if (flag & PMINFO_APPINFO_GET_DATA_CONTROL) {
-                       if (_appinfo_get_data_control(db, info->appid,
-                                               &info->datacontrol)) {
-                               ret = PMINFO_R_ERROR;
-                               goto catch;
-                       }
-               }
-
                if (flag & PMINFO_APPINFO_GET_METADATA) {
                        if (_appinfo_get_metadata(db, info->appid,
                                                &info->metadata)) {
@@ -1351,10 +1280,11 @@ static int _appinfo_get_filtered_foreach_appinfo(uid_t uid,
                                PMINFO_APPINFO_PROP_APP_DISABLE, false);
        }
 
-       ret = _appinfo_get_applications(uid, uid, locale, filter, flag, list);
+       ret = _appinfo_get_applications(uid, uid, locale, filter,
+                       flag | PMINFO_APPINFO_GET_BASICINFO, list);
        if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
                ret = _appinfo_get_applications(GLOBAL_USER, uid, locale,
-                               filter, flag, list);
+                               filter, flag | PMINFO_APPINFO_GET_BASICINFO, list);
 
        if (ret != PMINFO_R_OK) {
                g_hash_table_destroy(list);
index 27ea246..0ead442 100644 (file)
@@ -205,17 +205,17 @@ API char *getUserPkgParserDBPathUID(uid_t uid)
        }
        snprintf(pkgmgr_parser_db, sizeof(pkgmgr_parser_db),
                        "%s/.pkgmgr_parser.db", db_path);
-
-       if (uid != GLOBAL_USER && uid != ROOT_UID) {
-               tzplatform_set_user(uid);
-               gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
-               tzplatform_reset_user();
+       if (access(db_path, F_OK) != 0) {
+               if (uid != GLOBAL_USER && uid != ROOT_UID) {
+                       tzplatform_set_user(uid);
+                       gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
+                       tzplatform_reset_user();
+               }
+               /* just allow certain users to create the dbspace directory if needed. */
+               if (uid_caller == ROOT_UID || uid_caller == APPFW_UID ||
+                               uid_caller == uid)
+                       _mkdir_for_user(db_path, uid, gid);
        }
-
-       /* just allow certain users to create the dbspace directory if needed. */
-       if (uid_caller == ROOT_UID  || uid_caller == APPFW_UID || uid_caller == uid)
-               _mkdir_for_user(db_path, uid, gid);
-
        free(db_path);
 
        return strdup(pkgmgr_parser_db);
@@ -426,7 +426,7 @@ void _save_column_int(sqlite3_stmt *stmt, int idx, int *i)
        *i = sqlite3_column_int(stmt, idx);
 }
 
-void _save_column_str(sqlite3_stmt *stmt, int idx, char **str)
+inline void _save_column_str(sqlite3_stmt *stmt, int idx, char **str)
 {
        const char *val;
 
index 0531930..a9ba8db 100644 (file)
@@ -338,16 +338,16 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                pkgmgrinfo_filter_x *filter, int flag, GHashTable *packages)
 {
        static const char query_raw[] =
-               "SELECT DISTINCT pi.package, pi.package_version, "
-               "pi.install_location, pi.package_removable, "
-               "pi.package_preload, pi.package_readonly, pi.package_update, "
-               "pi.package_appsetting, pi.package_system, pi.package_type, "
-               "pi.package_size, pi.installed_time, pi.installed_storage, "
-               "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
-               "pi.root_path, pi.csc_path, pi.package_nodisplay, "
-               "pi.package_api_version, pi.package_support_disable, "
-               "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path, "
-               "pi.package_support_mode";
+               "SELECT DISTINCT pi.package, pi.installed_storage, pi.external_path";
+       static const char query_basic[] =
+               ", pi.package_version, pi.install_location, "
+               "pi.package_removable, pi.package_preload, pi.package_readonly, "
+               "pi.package_update, pi.package_appsetting, pi.package_system, "
+               "pi.package_type, pi.package_size, pi.installed_time, "
+               "pi.storeclient_id, pi.mainapp_id, pi.package_url, pi.root_path, "
+               "pi.csc_path, pi.package_nodisplay, pi.package_api_version, "
+               "pi.package_support_disable, pi.package_tep_name, "
+               "pi.package_zip_mount_file, pi.package_support_mode";
        static const char query_author[] =
                ", pi.author_name, pi.author_email, pi.author_href";
        static const char query_label[] =
@@ -377,6 +377,7 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
        sqlite3_stmt *stmt = NULL;
        pkgmgrinfo_filter_x *tmp_filter = NULL;
        bool is_check_storage = true;
+       const uid_t global_user_uid = GLOBAL_USER;
 
        dbpath = getUserPkgParserDBPathUID(uid);
        if (dbpath == NULL)
@@ -404,6 +405,10 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
 
        query_len = strlen(query_raw);
        snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
+       if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+               strncat(query, query_basic, MAX_QUERY_LEN - query_len - 1);
+               query_len += strlen(query_basic);
+       }
        if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
                strncat(query, query_author, MAX_QUERY_LEN - query_len - 1);
                query_len += strlen(query_author);
@@ -458,39 +463,36 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                }
                idx = 0;
                _save_column_str(stmt, idx++, &info->package);
-               if (g_hash_table_contains(packages,
-                                       (gconstpointer)info->package)) {
-                       free(info->package);
-                       free(info);
-                       info = NULL;
-                       continue;
-               }
-               _save_column_str(stmt, idx++, &info->version);
-               _save_column_str(stmt, idx++, &info->installlocation);
-               _save_column_str(stmt, idx++, &info->removable);
-               _save_column_str(stmt, idx++, &info->preload);
-               _save_column_str(stmt, idx++, &info->readonly);
-               _save_column_str(stmt, idx++, &info->update);
-               _save_column_str(stmt, idx++, &info->appsetting);
-               _save_column_str(stmt, idx++, &info->system);
-               _save_column_str(stmt, idx++, &info->type);
-               _save_column_str(stmt, idx++, &info->package_size);
-               _save_column_str(stmt, idx++, &info->installed_time);
                _save_column_str(stmt, idx++, &info->installed_storage);
-               _save_column_str(stmt, idx++, &info->storeclient_id);
-               _save_column_str(stmt, idx++, &info->mainapp_id);
-               _save_column_str(stmt, idx++, &info->package_url);
-               _save_column_str(stmt, idx++, &info->root_path);
-               _save_column_str(stmt, idx++, &info->csc_path);
-               _save_column_str(stmt, idx++, &info->nodisplay_setting);
-               _save_column_str(stmt, idx++, &info->api_version);
-               _save_column_str(stmt, idx++, &info->support_disable);
-               _save_column_str(stmt, idx++, &info->tep_name);
-               _save_column_str(stmt, idx++, &info->zip_mount_file);
                _save_column_str(stmt, idx++, &info->external_path);
-               _save_column_str(stmt, idx++, &info->support_mode);
+
+               if (flag & PMINFO_APPINFO_GET_BASICINFO) {
+                       _save_column_str(stmt, idx++, &info->version);
+                       _save_column_str(stmt, idx++, &info->installlocation);
+                       _save_column_str(stmt, idx++, &info->removable);
+                       _save_column_str(stmt, idx++, &info->preload);
+                       _save_column_str(stmt, idx++, &info->readonly);
+                       _save_column_str(stmt, idx++, &info->update);
+                       _save_column_str(stmt, idx++, &info->appsetting);
+                       _save_column_str(stmt, idx++, &info->system);
+                       _save_column_str(stmt, idx++, &info->type);
+                       _save_column_str(stmt, idx++, &info->package_size);
+                       _save_column_str(stmt, idx++, &info->installed_time);
+                       _save_column_str(stmt, idx++, &info->storeclient_id);
+                       _save_column_str(stmt, idx++, &info->mainapp_id);
+                       _save_column_str(stmt, idx++, &info->package_url);
+                       _save_column_str(stmt, idx++, &info->root_path);
+                       _save_column_str(stmt, idx++, &info->csc_path);
+                       _save_column_str(stmt, idx++, &info->nodisplay_setting);
+                       _save_column_str(stmt, idx++, &info->api_version);
+                       _save_column_str(stmt, idx++, &info->support_disable);
+                       _save_column_str(stmt, idx++, &info->tep_name);
+                       _save_column_str(stmt, idx++, &info->zip_mount_file);
+                       _save_column_str(stmt, idx++, &info->support_mode);
+               }
+
                info->for_all_users =
-                       strdup((uid != GLOBAL_USER) ? "false" : "true");
+                       strdup((uid != global_user_uid) ? "false" : "true");
 
                if (flag & PMINFO_PKGINFO_GET_AUTHOR) {
                        /* TODO : author should be retrieved at package_localized_info */
@@ -613,10 +615,11 @@ static int _pkginfo_get_filtered_foreach_pkginfo(uid_t uid,
                pkgmgrinfo_pkginfo_filter_add_bool(tmp_filter,
                                PMINFO_PKGINFO_PROP_PACKAGE_DISABLE, false);
 
-       ret = _pkginfo_get_packages(uid, locale, tmp_filter, flag, list);
+       ret = _pkginfo_get_packages(uid, locale, tmp_filter,
+                       flag | PMINFO_PKGINFO_GET_BASICINFO, list);
        if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
                ret = _pkginfo_get_packages(GLOBAL_USER, locale, tmp_filter,
-                               flag, list);
+                               flag | PMINFO_PKGINFO_GET_BASICINFO, list);
 
        if (ret != PMINFO_R_OK) {
                g_hash_table_destroy(list);
index b7809f8..21b4840 100644 (file)
@@ -394,14 +394,12 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p
                break;
        case E_PMINFO_APPINFO_PROP_APP_DISABLE:
                if (strcasecmp(node->value, "true") == 0)
-                       snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE OR "
-                                       "ai.app_id IN (SELECT app_id FROM package_app_info_for_uid "
-                                       "WHERE uid=%d AND is_disabled='true'))", uid);
+                       snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
+                                       "OR ui.is_disabled='true' COLLATE NOCASE)");
                else
-                       snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE AND "
-                                       "ai.app_id NOT IN (SELECT app_id FROM package_app_info_for_uid "
-                                       "WHERE uid=%d AND is_disabled='true'))", uid);
-               flag = E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID;
+                       snprintf(buf, MAX_QUERY_LEN, "(ai.app_disable=? COLLATE NOCASE " \
+                                       "AND (ui.is_disabled='false' COLLATE NOCASE " \
+                                       "OR ui.is_disabled IS NULL))");
                break;
        case E_PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE:
                snprintf(buf, MAX_QUERY_LEN, "ai.app_support_disable=? COLLATE NOCASE");
index c529ab2..333b5e3 100644 (file)
@@ -174,7 +174,6 @@ typedef enum _pkgmgrinfo_appinfo_join_flag {
        E_PMINFO_APPINFO_JOIN_CATEGORY = 0x0002,
        E_PMINFO_APPINFO_JOIN_APP_CONTROL = 0x0004,
        E_PMINFO_APPINFO_JOIN_METADATA = 0x0008,
-       E_PMINFO_APPINFO_JOIN_APPINFO_FOR_UID = 0x0010,
 } pkgmgrinfo_appinfo_join_flag;
 
 typedef struct _pkgmgr_pkginfo_x {