diff options
Diffstat (limited to 'ml/Query.h')
-rw-r--r-- | ml/Query.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/ml/Query.h b/ml/Query.h index 24c5fa3841..f228bd85e1 100644 --- a/ml/Query.h +++ b/ml/Query.h @@ -7,7 +7,7 @@ namespace ml { class Query { public: - Query(RRDDIM *RD) : RD(RD) { + Query(RRDDIM *RD) : RD(RD), Initialized(false) { Ops = &RD->tiers[0]->query_ops; } @@ -21,23 +21,26 @@ public: void init(time_t AfterT, time_t BeforeT) { Ops->init(RD->tiers[0]->db_metric_handle, &Handle, AfterT, BeforeT, TIER_QUERY_FETCH_SUM); + Initialized = true; } bool isFinished() { return Ops->is_finished(&Handle); } + ~Query() { + if (Initialized) + Ops->finalize(&Handle); + } + std::pair<time_t, CalculatedNumber> nextMetric() { STORAGE_POINT sp = Ops->next_metric(&Handle); return { sp.start_time, sp.sum / sp.count }; } - ~Query() { - Ops->finalize(&Handle); - } - private: RRDDIM *RD; + bool Initialized; struct rrddim_query_ops *Ops; struct rrddim_query_handle Handle; |