Browse Source

perf(tagstore): apply a lower bound to get_groups_user_counts. (#16710)

* perf(tagstore): apply a lower bound to get_groups_user_counts.

* invert timedelta math because there's no way to flush buffers to update first_seen.

* hey look the same test copied over
James Cunningham 5 years ago
parent
commit
2f5516bd8c

+ 3 - 3
src/sentry/models/group.py

@@ -463,9 +463,9 @@ class Group(Model):
         return "%s - %s" % (self.qualified_short_id.encode("utf-8"), self.title.encode("utf-8"))
 
     def count_users_seen(self):
-        return tagstore.get_groups_user_counts([self.project_id], [self.id], environment_ids=None)[
-            self.id
-        ]
+        return tagstore.get_groups_user_counts(
+            [self.project_id], [self.id], environment_ids=None, start=self.first_seen
+        )[self.id]
 
     @classmethod
     def calculate_score(cls, times_seen, last_seen):

+ 1 - 1
tests/snuba/api/endpoints/test_organization_group_index.py

@@ -1091,7 +1091,7 @@ class GroupUpdateTest(APITestCase, SnubaTestCase):
                 data={
                     "fingerprint": ["put-me-in-group-1"],
                     "user": {"id": six.binary_type(i)},
-                    "timestamp": iso_format(self.min_ago - timedelta(seconds=i)),
+                    "timestamp": iso_format(self.min_ago + timedelta(seconds=i)),
                 },
                 project_id=self.project.id,
             )

+ 1 - 1
tests/snuba/api/endpoints/test_project_group_index.py

@@ -978,7 +978,7 @@ class GroupUpdateTest(APITestCase, SnubaTestCase):
                 data={
                     "fingerprint": ["put-me-in-group-1"],
                     "user": {"id": six.binary_type(i)},
-                    "timestamp": iso_format(self.min_ago - timedelta(seconds=i)),
+                    "timestamp": iso_format(self.min_ago + timedelta(seconds=i)),
                 },
                 project_id=self.project.id,
             )