1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/data/estimate.py
Joseph Schorr 1b023b8c2f Fix performance of the global prom stats worker queries (#238)
- Change the counts to use the MySQL information schema for estimates
- Change the lookup of active users to skip the unnecessary heavy filter
2020-02-27 13:16:35 -05:00

12 lines
502 B
Python

def mysql_estimate_row_count(model_cls, db):
""" Uses the information_schema to retrieve the row count for a table. """
query = "SELECT table_rows FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = %s"
cursor = db.execute_sql(query, (model_cls._meta.table_name,))
res = cursor.fetchone()
return res[0]
def normal_row_count(model_cls, db):
""" Uses a normal .count() to retrieve the row count for a model. """
return model_cls.select().count()