| 160 | } |
| 161 | |
| 162 | func (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 | |
| 187 | func (c *Client) flushBouncers(ctx context.Context, authType string, duration *time.Duration) { |
| 188 | if duration == nil { |