From d8302174640d530f38fa0ea43eb8070350720eb0 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 6 May 2025 19:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E8=B6=85=E5=A4=A7=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- .../include/bundle_active_usage_database.h | 3 +++ .../src/bundle_active_usage_database.cpp | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 41123f4..95427ae 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -126,6 +126,9 @@ private: const int64_t endTime, const int32_t databaseType, const int32_t index, const int32_t startIndex, const int32_t endIndex, const int32_t userId, std::vector &queryCondition, std::string &queryPackageSql); + void GetCurrentBundleStats(int64_t currentPackageTime, + std::shared_ptr& bundleActiveResult, + std::shared_ptr& intervalStats); bool GetDbIndex(const int64_t beginTime, const int64_t endTime, const int32_t databaseType, int32_t &startIndex, int32_t &endIndex); diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 2a42d0a..4b611a6 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1052,9 +1052,21 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa if (bundleActiveResult == nullptr) { return nullptr; } + GetCurrentBundleStats(currentPackageTime, bundleActiveResult, intervalStats); + bundleActiveResult->Close(); + if (databaseType == DAILY_DATABASE_INDEX) { + eventBeginTime_ = currentPackageTime; + } + int64_t systemTime = GetSystemTimeMs(); + intervalStats->lastTimeSaved_ = systemTime; + return intervalStats; +} + +void BundleActiveUsageDatabase::GetCurrentBundleStats(int64_t currentPackageTime, + shared_ptr& bundleActiveResult, shared_ptr& intervalStats) +{ int32_t tableRowNumber; bundleActiveResult->GetRowCount(tableRowNumber); - map> bundleStats; int64_t relativeLastTimeUsed; int64_t relativeLastTimeFrontServiceUsed; for (int32_t i = 0; i < tableRowNumber; i++) { @@ -1073,16 +1085,9 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa bundleActiveResult->GetInt(PACKAGE_LOG_UID_COLUMN_INDEX, usageStats->uid_); string bundleStatsKey = usageStats->bundleName_ + std::to_string(usageStats->uid_); BundleActiveBundleMgrHelper::GetInstance()->InsertPackageUid(usageStats->bundleName_, usageStats->uid_); - bundleStats.insert(pair>(bundleStatsKey, usageStats)); - } - bundleActiveResult->Close(); - intervalStats->bundleStats_ = bundleStats; - if (databaseType == DAILY_DATABASE_INDEX) { - eventBeginTime_ = currentPackageTime; + intervalStats->bundleStats_.insert( + pair>(bundleStatsKey, usageStats)); } - int64_t systemTime = GetSystemTimeMs(); - intervalStats->lastTimeSaved_ = systemTime; - return intervalStats; } void BundleActiveUsageDatabase::FlushEventInfo(uint32_t databaseType, BundleActivePeriodStats &stats) -- Gitee