Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move date logic into generated query (out of queryset)

  • Loading branch information...
commit 71a7d5bee9bf24c91f7dda3e69dd9b641a69541a 1 parent 1a29768
@dcramer dcramer authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/sentry/manager.py
View
9 src/sentry/manager.py
@@ -728,6 +728,8 @@ def get_accelerated(self, queryset=None, minutes=15):
after_group = after_group.split(' ORDER BY ')[0]
# TODO: extract(epoch) is only available in pgsql
+ # TODO: the subquery needs some conditions from the base query for efficiency
+ # such as project IN (x) or group_id IN (x)
query = """
SELECT (SUM(%(mcbm_tbl)s.times_seen) * (%(norm)f / (extract(epoch from now() - %(mcbm_tbl)s.date) / 60)) + 1.0) / (COALESCE(z.rate, 0) + 1.0) as accel,
(COALESCE(z.rate, 0) + 1.0) as prev_rate,
@@ -738,7 +740,9 @@ def get_accelerated(self, queryset=None, minutes=15):
AND now() - %(min_time)s
GROUP BY a.group_id) as z
ON z.group_id = %(mcbm_tbl)s.group_id
- WHERE %(before_group)s
+ WHERE %(mcbm_tbl)s.date BETWEEN now() - %(min_time)s
+ AND now() - %(offset_time)s
+ AND %(before_group)s
GROUP BY prev_rate, %(mcbm_tbl)s.date, %(after_group)s
HAVING SUM(%(mcbm_tbl)s.times_seen) > 0
ORDER BY accel DESC
@@ -747,8 +751,9 @@ def get_accelerated(self, queryset=None, minutes=15):
before_where=before_where,
before_group=before_group,
after_group=after_group,
+ offset_time=minute_clause % (1,),
min_time=minute_clause % (minutes + 1,),
- max_time=minute_clause % (minutes * 4,),
+ max_time=minute_clause % (minutes * (60 / normalization),),
norm=normalization,
)
return RawQuerySet(self, query, params)
Please sign in to comment.
Something went wrong with that request. Please try again.