From c217e1851dca4da562928c3719a57f048a8af688 Mon Sep 17 00:00:00 2001 From: baozeyu Date: Sat, 14 Sep 2024 14:26:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=89=93=E7=82=B9=E9=99=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: baozeyu Change-Id: I0e4dbed404a3d8d6bc608a1130c2d2173bc808eb --- .../common/notification_analytics_util.cpp | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index f962ea08c..05cc9a2b2 100644 --- a/services/ans/src/common/notification_analytics_util.cpp +++ b/services/ans/src/common/notification_analytics_util.cpp @@ -31,9 +31,17 @@ constexpr const int32_t DELETE_ERROR_EVENT_CODE = 5; constexpr const int32_t MODIFY_ERROR_EVENT_CODE = 6; constexpr const int32_t DEFAULT_ERROR_EVENT_COUNT = 6; constexpr const int32_t DEFAULT_ERROR_EVENT_TIME = 60; +constexpr const int32_t PUBLISH_ERROR_EVENT_COUNT = 3; +constexpr const int32_t PUBLISH_ERROR_EVENT_TIME = 60; +constexpr const int32_t DELETE_ERROR_EVENT_COUNT = 3; +constexpr const int32_t DELETE_ERROR_EVENT_TIME = 60; const static std::string NOTIFICATION_EVENT_PUSH_AGENT = "notification.event.PUSH_AGENT"; static std::mutex reportFlowControlMutex_; -static std::map> flowControlTimestampMap_; +static std::map> flowControlTimestampMap_ = { + {MODIFY_ERROR_EVENT_CODE, {}}, + {PUBLISH_ERROR_EVENT_CODE, {}}, + {DELETE_ERROR_EVENT_CODE, {}}, +}; HaMetaMessage::HaMetaMessage(uint32_t sceneId, uint32_t branchId) : sceneId_(sceneId), branchId_(branchId) @@ -153,8 +161,14 @@ void NotificationAnalyticsUtil::CommonNotificationEvent(const sptr extraInfo = std::make_shared(); std::string reason = message.Build(); extraInfo->SetParam("reason", AAFwk::String::Box(reason)); @@ -256,27 +274,20 @@ bool NotificationAnalyticsUtil::ReportFlowControl(const int32_t reportType) { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); std::lock_guard lock(reportFlowControlMutex_); - std::list list = GetFlowListByType(reportType); + auto iter = flowControlTimestampMap_.find(reportType); + if (iter == flowControlTimestampMap_.end()) { + return false; + } + auto& list = iter->second; FlowControllerOption option = GetFlowOptionByType(reportType); RemoveExpired(list, now, option.time); if (list.size() >= option.count) { return false; } list.push_back(now); - flowControlTimestampMap_[reportType] = list; return true; } -std::list NotificationAnalyticsUtil::GetFlowListByType(const int32_t reportType) -{ - std::list res; - auto iter = flowControlTimestampMap_.find(reportType); - if (iter != flowControlTimestampMap_.end()) { - res = iter->second; - } - return res; -} - void NotificationAnalyticsUtil::RemoveExpired(std::list &list, const std::chrono::system_clock::time_point &now, int32_t time) { @@ -298,6 +309,14 @@ FlowControllerOption NotificationAnalyticsUtil::GetFlowOptionByType(const int32_ option.count = DEFAULT_ERROR_EVENT_COUNT; option.time = DEFAULT_ERROR_EVENT_TIME; break; + case PUBLISH_ERROR_EVENT_CODE: + option.count = PUBLISH_ERROR_EVENT_COUNT; + option.time = PUBLISH_ERROR_EVENT_TIME; + break; + case DELETE_ERROR_EVENT_CODE: + option.count = DELETE_ERROR_EVENT_COUNT; + option.time = DELETE_ERROR_EVENT_TIME; + break; default: option.count = DEFAULT_ERROR_EVENT_COUNT; option.time = DEFAULT_ERROR_EVENT_TIME; -- Gitee