Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Flush analytics event log on every persist call.

Kishore Nallan71f905f18c5a
diff --git a/include/analytics_manager.h b/include/analytics_manager.h
index b5bdf4b2..59cd82bc 100644
--- a/include/analytics_manager.h
+++ b/include/analytics_manager.h
@@ -122,7 +122,6 @@ private:
std::ofstream analytics_logs;
bool isRateLimitTestEnabled = false;
- uint64_t analytics_logs_count = 0;
AnalyticsManager() {}
@@ -182,8 +181,6 @@ public:
void persist_popular_events(ReplicationState *raft_server, uint64_t prev_persistence_s);
- nlohmann::json get_events(const std::string& coll, const std::string& event_type);
-
std::unordered_map<std::string, counter_event_t> get_popular_clicks();
void add_nohits_query(const std::string& query_collection,
diff --git a/src/analytics_manager.cpp b/src/analytics_manager.cpp
index 53b15b74..208708e5 100644
--- a/src/analytics_manager.cpp
+++ b/src/analytics_manager.cpp
@@ -501,15 +501,13 @@ void AnalyticsManager::persist_events(ReplicationState *raft_server, uint64_t pr
if (event.event_type == QUERY_CLICK) {
analytics_logs << event.timestamp << "\t" << event.user_id << "\t"
<< 'C' << "\t" << event.doc_id << "\t"
- << collection << event.query << "\t" << "\n";
+ << collection << "\t" << event.query << "\n";
} else if (event.event_type == QUERY_PURCHASE) {
analytics_logs << event.timestamp << "\t" << event.user_id << "\t"
<< 'P' << "\t" << event.doc_id << "\t" << collection << "\n";
}
- ++analytics_logs_count;
- if(analytics_logs_count % 10 == 0) {
- analytics_logs << std::flush;
- }
+
+ analytics_logs << std::flush;
}
}
}
@@ -595,25 +593,6 @@ std::unordered_map<std::string, counter_event_t> AnalyticsManager::get_popular_c
return counter_events;
}
-nlohmann::json AnalyticsManager::get_events(const std::string& coll, const std::string& event_type) {
- std::unique_lock lk(mutex);
- nlohmann::json event_json;
- nlohmann::json result_json = nlohmann::json::array();
-
- auto query_collection_events_it = query_collection_events.find(coll);
- if (query_collection_events_it != query_collection_events.end()) {
- auto events = query_collection_events_it->second;
- for (const auto &event: events) {
- if(event.event_type == event_type) {
- event.to_json(event_json);
- result_json.push_back(event_json);
- }
- }
- }
-
- return result_json;
-}
-
void AnalyticsManager::resetToggleRateLimit(bool toggle) {
events_cache.clear();
isRateLimitTestEnabled = toggle;