mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 13:42:26 +08:00
pass only analytics dir instead of db ptr
This commit is contained in:
parent
09e88c7c20
commit
35988725f5
@ -195,7 +195,7 @@ public:
|
||||
AnalyticsManager(AnalyticsManager const&) = delete;
|
||||
void operator=(AnalyticsManager const&) = delete;
|
||||
|
||||
void init(Store* store, Store* analytics_store);
|
||||
void init(Store* store, const std::string& analytics_dir="");
|
||||
|
||||
void run(ReplicationState* raft_server);
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "collection_manager.h"
|
||||
#include "lru/lru.hpp"
|
||||
#include "string_utils.h"
|
||||
#include "tsconfig.h"
|
||||
|
||||
LRU::Cache<std::string, event_cache_t> events_cache;
|
||||
#define EVENTS_RATE_LIMIT_SEC 60
|
||||
@ -609,6 +608,9 @@ void AnalyticsManager::persist_popular_events(ReplicationState *raft_server, uin
|
||||
void AnalyticsManager::stop() {
|
||||
quit = true;
|
||||
cv.notify_all();
|
||||
if(analytics_store) {
|
||||
delete analytics_store;
|
||||
}
|
||||
}
|
||||
|
||||
void AnalyticsManager::dispose() {
|
||||
@ -627,12 +629,11 @@ void AnalyticsManager::dispose() {
|
||||
nohits_queries.clear();
|
||||
}
|
||||
|
||||
void AnalyticsManager::init(Store* store, Store* analytics_store) {
|
||||
void AnalyticsManager::init(Store* store, const std::string& analytics_dir) {
|
||||
this->store = store;
|
||||
this->analytics_store = analytics_store;
|
||||
|
||||
if(analytics_store) {
|
||||
const auto analytics_dir = Config::get_instance().get_analytics_dir();
|
||||
if(!analytics_dir.empty()) {
|
||||
this->analytics_store = new Store(analytics_dir, 24 * 60 * 60, 1024, true);
|
||||
const auto analytics_log_path = analytics_dir + "/analytics_events.tsv";
|
||||
|
||||
analytics_logs.open(analytics_log_path, std::ofstream::out | std::ofstream::app);
|
||||
|
@ -402,15 +402,12 @@ int run_server(const Config & config, const std::string & version, void (*master
|
||||
|
||||
//analytics DB for storing query click events
|
||||
std::unique_ptr<Store> analytics_store = nullptr;
|
||||
if(!analytics_dir.empty()) {
|
||||
analytics_store.reset(new Store(analytics_dir, 24 * 60 * 60, 1024, true));
|
||||
}
|
||||
|
||||
curl_global_init(CURL_GLOBAL_SSL);
|
||||
HttpClient & httpClient = HttpClient::get_instance();
|
||||
httpClient.init(config.get_api_key());
|
||||
|
||||
AnalyticsManager::get_instance().init(&store, analytics_store.get());
|
||||
AnalyticsManager::get_instance().init(&store, analytics_dir);
|
||||
|
||||
server = new HttpServer(
|
||||
version,
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
class AnalyticsManagerTest : public ::testing::Test {
|
||||
protected:
|
||||
Store *store, *analytics_store;
|
||||
Store *store;
|
||||
CollectionManager& collectionManager = CollectionManager::get_instance();
|
||||
std::atomic<bool> quit = false;
|
||||
|
||||
@ -25,11 +25,10 @@ protected:
|
||||
system("mkdir -p /tmp/typesense_test/models");
|
||||
|
||||
store = new Store(state_dir_path);
|
||||
analytics_store = new Store(analytics_db_path);
|
||||
collectionManager.init(store, 1.0, "auth_key", quit);
|
||||
collectionManager.load(8, 1000);
|
||||
|
||||
analyticsManager.init(store, analytics_store);
|
||||
analyticsManager.init(store, analytics_db_path);
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
@ -39,7 +38,7 @@ protected:
|
||||
virtual void TearDown() {
|
||||
collectionManager.dispose();
|
||||
delete store;
|
||||
delete analytics_store;
|
||||
analyticsManager.stop();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
class CollectionManagerTest : public ::testing::Test {
|
||||
protected:
|
||||
Store *store, *analytics_store;
|
||||
Store *store;
|
||||
CollectionManager & collectionManager = CollectionManager::get_instance();
|
||||
std::atomic<bool> quit = false;
|
||||
Collection *collection1;
|
||||
@ -23,11 +23,10 @@ protected:
|
||||
system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());
|
||||
|
||||
store = new Store(state_dir_path);
|
||||
analytics_store = new Store(analytics_db_path);
|
||||
collectionManager.init(store, 1.0, "auth_key", quit);
|
||||
collectionManager.load(8, 1000);
|
||||
|
||||
AnalyticsManager::get_instance().init(store, analytics_store);
|
||||
AnalyticsManager::get_instance().init(store, analytics_db_path);
|
||||
|
||||
schema = R"({
|
||||
"name": "collection1",
|
||||
@ -64,6 +63,7 @@ protected:
|
||||
collectionManager.drop_collection("collection1");
|
||||
collectionManager.dispose();
|
||||
delete store;
|
||||
AnalyticsManager::get_instance().stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
class CoreAPIUtilsTest : public ::testing::Test {
|
||||
protected:
|
||||
Store *store, *analytics_store;
|
||||
Store *store;
|
||||
CollectionManager & collectionManager = CollectionManager::get_instance();
|
||||
std::atomic<bool> quit = false;
|
||||
|
||||
@ -27,13 +27,12 @@ protected:
|
||||
system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());
|
||||
|
||||
store = new Store(state_dir_path);
|
||||
analytics_store = new Store(analytics_db_path);
|
||||
collectionManager.init(store, 1.0, "auth_key", quit);
|
||||
collectionManager.load(8, 1000);
|
||||
|
||||
ConversationModelManager::init(store);
|
||||
ConversationManager::get_instance().init(store);
|
||||
analyticsManager.init(store, analytics_store);
|
||||
analyticsManager.init(store, analytics_db_path);
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
@ -43,7 +42,7 @@ protected:
|
||||
virtual void TearDown() {
|
||||
collectionManager.dispose();
|
||||
delete store;
|
||||
delete analytics_store;
|
||||
analyticsManager.stop();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user