diff --git a/services/ans/src/common/notification_analytics_util.cpp b/services/ans/src/common/notification_analytics_util.cpp index f962ea08c6233ce1444db0604a839becb29b55ba..05cc9a2b204536e1d526445868395570d54d19ac 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;