@cryptotaxi247 / netdata-1 / commits / 08f8695a5

Move initial snapshot_proto generation inside the loop (#11719)

Emmanuel Vasilakis committed Nov 1, 2021 at 08:58 UTC 08f8695a5b344f7ace09aa97c1a2ec3fb08a6e9d
1 file changed +6 -4
database/sqlite/sqlite_aclk_alert.c
+6 -4
@@ -778,8 +778,7 @@ void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, stru
778 alarm_snap.chunks = chunks;
779 alarm_snap.chunk = chunk;
780
781 - alarm_snapshot_proto_ptr_t snapshot_proto;
782 - snapshot_proto = generate_alarm_snapshot_proto(&alarm_snap);
781 + alarm_snapshot_proto_ptr_t snapshot_proto = NULL;
782
783 for (; ae; ae = ae->next) {
784 if (likely(ae->updated_by_id))
@@ -791,15 +790,18 @@ void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, stru
790 if (have_recent_alarm(host, ae->alarm_id, ae->unique_id))
791 continue;
792
793 + cnt++;
794 +
795 struct alarm_log_entry alarm_log;
796 alarm_log.node_id = wc->node_id;
797 alarm_log.claim_id = claim_id;
798
799 + if (!snapshot_proto)
800 + snapshot_proto = generate_alarm_snapshot_proto(&alarm_snap);
801 +
802 health_alarm_entry2proto_nolock(&alarm_log, ae, host);
803 add_alarm_log_entry2snapshot(snapshot_proto, &alarm_log);
804
801 - cnt++;
802 -
805 if (cnt == ALARM_EVENTS_PER_CHUNK) {
806 aclk_send_alarm_snapshot(snapshot_proto);
807