Permalink
Browse files

Remove extra accelerated test and correct now clause for mysql

  • Loading branch information...
1 parent 425b654 commit bc87c301eafdfd9bf8a15a52d4a44f7ed6ca924b @dcramer dcramer committed Sep 20, 2012
Showing with 13 additions and 16 deletions.
  1. +10 −7 src/sentry/manager.py
  2. +3 −9 tests/sentry/manager/tests.py
View
@@ -716,17 +716,19 @@ def get_accelerated(self, queryset=None, minutes=15):
# way to get the epoch from a datetime/interval
if engine.startswith('mysql'):
minute_clause = "interval %s minute"
- epoch_clause = "unix_timestamp(now()) - unix_timestamp(%(mcbm_tbl)s.date)"
+ epoch_clause = "unix_timestamp(utc_timestamp()) - unix_timestamp(%(mcbm_tbl)s.date)"
+ now_clause = 'utc_timestamp()'
else:
minute_clause = "interval '%s minutes'"
epoch_clause = "extract(epoch from now()) - extract(epoch from %(mcbm_tbl)s.date)"
+ now_clause = 'now()'
epoch_clause = epoch_clause % dict(mcbm_tbl=mcbm_tbl)
queryset = queryset.extra(
where=[
- "%s.date >= now() - %s" % (mcbm_tbl, minute_clause % (minutes + 1, )),
- "%s.date <= now() - %s" % (mcbm_tbl, minute_clause % (1, ))
+ "%s.date >= %s - %s" % (mcbm_tbl, now_clause, minute_clause % (minutes + 1, )),
+ "%s.date <= %s - %s" % (mcbm_tbl, now_clause, minute_clause % (1, ))
],
).annotate(x=Sum('messagecountbyminute__times_seen')).order_by('id')
@@ -744,12 +746,12 @@ def get_accelerated(self, queryset=None, minutes=15):
%(before_where)s
LEFT JOIN (SELECT a.group_id, SUM(a.times_seen) / COUNT(a.times_seen) / %(norm)f as rate
FROM %(mcbm_tbl)s as a
- WHERE a.date BETWEEN now() - %(max_time)s
- AND now() - %(min_time)s
+ WHERE a.date BETWEEN %(now)s - %(max_time)s
+ AND %(now)s - %(min_time)s
GROUP BY a.group_id) as z
ON z.group_id = %(mcbm_tbl)s.group_id
- WHERE %(mcbm_tbl)s.date BETWEEN now() - %(min_time)s
- AND now() - %(offset_time)s
+ WHERE %(mcbm_tbl)s.date BETWEEN %(now)s - %(min_time)s
+ AND %(now)s - %(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
@@ -764,6 +766,7 @@ def get_accelerated(self, queryset=None, minutes=15):
max_time=minute_clause % (minutes * (60 / normalization),),
norm=normalization,
epoch_clause=epoch_clause,
+ now=now_clause,
)
return RawQuerySet(self, query, params)
@@ -183,14 +183,6 @@ def test_updates_group(self):
self.assertEquals(group.last_seen.replace(microsecond=0), event.datetime.replace(microsecond=0))
self.assertEquals(group.message, 'foo bar')
- def test_get_accelerrated(self):
- if not has_trending():
- return
- group = Group.objects.from_kwargs(1, message='foo', checksum='a' * 32).group
- group_list = list(Group.objects.get_accelerated(Group.objects.all(), minutes=settings.MINUTE_NORMALIZATION)[0:100])
- self.assertEquals(len(group_list), 1)
- self.assertEquals(group_list[0], group)
-
def test_add_tags(self):
event = Group.objects.from_kwargs(1, message='rrr')
group = event.group
@@ -244,10 +236,12 @@ def test_accelerated_works_at_all(self):
now = timezone.now() - datetime.timedelta(minutes=5)
project = Project.objects.all()[0]
group = Group.objects.create(status=0, project=project, message='foo', checksum='a' * 32)
+ group2 = Group.objects.create(status=0, project=project, message='foo', checksum='b' * 32)
MessageCountByMinute.objects.create(project=project, group=group, date=now, times_seen=50)
+ MessageCountByMinute.objects.create(project=project, group=group2, date=now, times_seen=40)
base_qs = Group.objects.filter(
status=0,
)
results = list(Group.objects.get_accelerated(base_qs)[:25])
- self.assertEquals(results, [group])
+ self.assertEquals(results, [group, group2])

0 comments on commit bc87c30

Please sign in to comment.