From a98ec61e848299c03f80743a9b76456a13351c22 Mon Sep 17 00:00:00 2001 From: Adam Dobrawy Date: Sun, 14 May 2017 22:06:34 +0200 Subject: [PATCH] Fix count torrents on homepage in magneticow --- magneticow/magneticow/magneticow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magneticow/magneticow/magneticow.py b/magneticow/magneticow/magneticow.py index bf9b98c..e5ab3fe 100644 --- a/magneticow/magneticow/magneticow.py +++ b/magneticow/magneticow/magneticow.py @@ -74,8 +74,9 @@ def requires_auth(f): @requires_auth def home_page(): 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 ;") - n_torrents = cur.fetchone()[0] + n_torrents = cur.fetchone()[0] or 0 return flask.render_template("homepage.html", n_torrents=n_torrents)