Alerting: Increase alert rule operation perf by replacing subquery with threshold calculation (#53069)
Alerting: Increase alert rule operation perf by replacing subquery with threshold calculation (#53069)

* Replace subquery with threshold calculation

* Use offset/limit to account for orgs with large gaps in IDs

* Collapse into one statement

* Drop dead constants

* Revert to 2 query approach

* Drop unused consts again
grafana/grafana,grafana/grafana,grafana/grafana,grafana/grafana,grafana/grafana,grafana/grafana,grafana/grafana