mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 21:22:25 +08:00
return empty array on GET when analytics are not enabled
This commit is contained in:
parent
40d55bc340
commit
2de56ee39a
@ -151,7 +151,7 @@ public:
|
||||
|
||||
void persist_click_events(ReplicationState *raft_server, uint64_t prev_persistence_s);
|
||||
|
||||
Option<nlohmann::json> get_click_events();
|
||||
nlohmann::json get_click_events();
|
||||
|
||||
Option<bool> write_click_event_to_store(nlohmann::json& click_event_json);
|
||||
|
||||
|
@ -424,24 +424,22 @@ std::unordered_map<std::string, PopularQueries*> AnalyticsManager::get_popular_q
|
||||
return popular_queries;
|
||||
}
|
||||
|
||||
Option<nlohmann::json> AnalyticsManager::get_click_events() {
|
||||
nlohmann::json AnalyticsManager::get_click_events() {
|
||||
std::unique_lock lk(mutex);
|
||||
std::vector<std::string> click_event_jsons;
|
||||
nlohmann::json result_json = nlohmann::json::array();
|
||||
|
||||
if (analytics_store) {
|
||||
analytics_store->scan_fill(std::string(CLICK_EVENT) + "_", std::string(CLICK_EVENT) + "`",
|
||||
click_event_jsons);
|
||||
} else {
|
||||
return Option<nlohmann::json>(500, "Analytics DB not initialized.");
|
||||
|
||||
for (const auto &click_event_json: click_event_jsons) {
|
||||
nlohmann::json click_event = nlohmann::json::parse(click_event_json);
|
||||
result_json.push_back(click_event);
|
||||
}
|
||||
}
|
||||
|
||||
nlohmann::json result_json = nlohmann::json::array();
|
||||
for (const auto &click_event_json: click_event_jsons) {
|
||||
nlohmann::json click_event = nlohmann::json::parse(click_event_json);
|
||||
result_json.push_back(click_event);
|
||||
}
|
||||
|
||||
|
||||
return Option<nlohmann::json>(result_json);
|
||||
return result_json;
|
||||
}
|
||||
|
||||
Option<bool> AnalyticsManager::write_click_event_to_store(nlohmann::json &click_event_jsons) {
|
||||
|
@ -2800,13 +2800,13 @@ bool put_conversation_model(const std::shared_ptr<http_req>& req, const std::sha
|
||||
return true;
|
||||
}
|
||||
bool get_click_events(const std::shared_ptr<http_req>& req, const std::shared_ptr<http_res>& res) {
|
||||
auto click_events_op = AnalyticsManager::get_instance().get_click_events();
|
||||
auto click_events = AnalyticsManager::get_instance().get_click_events();
|
||||
|
||||
if(!click_events_op.ok()) {
|
||||
res->set(click_events_op.code(), click_events_op.error());
|
||||
if(click_events.empty()) {
|
||||
res->set_400(click_events.dump());
|
||||
}
|
||||
|
||||
res->set_200(click_events_op.get().dump());
|
||||
res->set_200(click_events.dump());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user