MCPcopy
hub / github.com/crowdsecurity/crowdsec / FlushOrphans

Method FlushOrphans

pkg/database/flush.go:162–185  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

160}
161
162func (c *Client) FlushOrphans(ctx context.Context) {
163 /* While it has only been linked to some very corner-case bug : https://github.com/crowdsecurity/crowdsec/issues/778 */
164 /* We want to take care of orphaned events for which the parent alert/decision has been deleted */
165 eventsCount, err := c.Ent.Event.Delete().Where(event.Not(event.HasOwner())).Exec(ctx)
166 if err != nil {
167 c.Log.Warningf("error while deleting orphan events: %s", err)
168 return
169 }
170
171 if eventsCount > 0 {
172 c.Log.Infof("%d deleted orphan events", eventsCount)
173 }
174
175 eventsCount, err = c.Ent.Decision.Delete().Where(
176 decision.Not(decision.HasOwner())).Where(decision.UntilLTE(time.Now().UTC())).Exec(ctx)
177 if err != nil {
178 c.Log.Warningf("error while deleting orphan decisions: %s", err)
179 return
180 }
181
182 if eventsCount > 0 {
183 c.Log.Infof("%d deleted orphan decisions", eventsCount)
184 }
185}
186
187func (c *Client) flushBouncers(ctx context.Context, authType string, duration *time.Duration) {
188 if duration == nil {

Callers 2

FlushAlertsMethod · 0.95

Calls 8

NotFunction · 0.92
HasOwnerFunction · 0.92
NotFunction · 0.92
HasOwnerFunction · 0.92
UntilLTEFunction · 0.92
ExecMethod · 0.45
WhereMethod · 0.45
DeleteMethod · 0.45

Tested by 1