Skip to content

Commit c7209a3

Browse files
authored
perf(db): Count hits on a replica instead of the primary postgres (#32178)
This can be an expensive query, and it doesn't need to be 100% accurate, so we can safely use a replica here. Replag is typically low anyway, so this shouldn't have any noticeable customer impact.
1 parent bfdb4da commit c7209a3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/sentry/api/paginator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def count_hits(self, max_hits):
190190
h_sql, h_params = hits_query.sql_with_params()
191191
except EmptyResultSet:
192192
return 0
193-
cursor = connections[self.queryset.db].cursor()
193+
cursor = connections[self.queryset.using_replica().db].cursor()
194194
cursor.execute(f"SELECT COUNT(*) FROM ({h_sql}) as t", h_params)
195195
return cursor.fetchone()[0]
196196

0 commit comments

Comments
 (0)