Metrics: Fail silently if estimated count returns no result

This commit is contained in:
Raphael Michel
2021-04-19 23:28:58 +02:00
parent 9f9d047293
commit 5faf2019e8

View File

@@ -249,6 +249,8 @@ def estimate_count_fast(type):
cursor = connection.cursor()
cursor.execute("select reltuples from pg_class where relname='%s';" % type._meta.db_table)
row = cursor.fetchone()
if not row:
return 0
return int(row[0])
else:
return type.objects.count()