From bb4ad57f980850e1645fa23e6045a10adc22f617 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 10 Mar 2024 11:53:17 +0100 Subject: [PATCH] Continued: - row[] does already contain named keys, e.g. 'total_websites' so let's alias the COUNT() statement to such key name which reduces some code - renamed 'blocks_recorded' to 'total_blocks' --- daemon.py | 9 ++------- templates/views/index.html | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/daemon.py b/daemon.py index 7d7626f..0f87bec 100755 --- a/daemon.py +++ b/daemon.py @@ -56,15 +56,10 @@ templates = Jinja2Templates(directory="templates") @router.get(config.get("base_url") + "/api/info.json", response_class=JSONResponse) def api_info(): - database.cursor.execute("SELECT (SELECT COUNT(domain) FROM instances), (SELECT COUNT(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb', 'smithereen', 'vebinet')), (SELECT COUNT(blocker) FROM blocks), (SELECT COUNT(domain) FROM instances WHERE last_error_details IS NOT NULL)") + database.cursor.execute("SELECT (SELECT COUNT(domain) AS total_websites FROM instances), (SELECT COUNT(domain) AS supported_instances FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus', 'neodb', 'smithereen', 'vebinet')), (SELECT COUNT(blocker) FROM blocks) AS total_blocks, (SELECT COUNT(domain) AS erroneous_instances FROM instances WHERE last_error_details IS NOT NULL)") row = database.cursor.fetchone() - return JSONResponse(status_code=200, content={ - "total_websites" : row[0], - "supported_instances": row[1], - "blocks_recorded" : row[2], - "erroneous_instances": row[3], - }) + return JSONResponse(status_code=200, content=row) @router.get(config.get("base_url") + "/api/scoreboard.json", response_class=JSONResponse) def api_scoreboard(mode: str, amount: int): diff --git a/templates/views/index.html b/templates/views/index.html index 4974c1b..0b607dc 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -92,7 +92,7 @@ {{info.total_websites}} {{info.supported_instances}} - {{info.blocks_recorded}} + {{info.total_blocks}} {{info.erroneous_instances}} -- 2.39.5