Fix count torrents on homepage in magneticow

This commit is contained in:
Adam Dobrawy 2017-05-14 22:06:34 +02:00 committed by GitHub
parent a3adf88b45
commit a98ec61e84

View File

@ -74,8 +74,9 @@ def requires_auth(f):
@requires_auth @requires_auth
def home_page(): def home_page():
with magneticod_db: with magneticod_db:
# COUNT(ROWID) is much more inefficient since it scans the whole table, so use MAX(ROWID)
cur = magneticod_db.execute("SELECT MAX(ROWID) FROM torrents ;") cur = magneticod_db.execute("SELECT MAX(ROWID) FROM torrents ;")
n_torrents = cur.fetchone()[0] n_torrents = cur.fetchone()[0] or 0
return flask.render_template("homepage.html", n_torrents=n_torrents) return flask.render_template("homepage.html", n_torrents=n_torrents)