From f422d957177563a89a4b7792fe395588bb157e10 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 7 Apr 2025 14:56:02 -0400 Subject: Fixed bug where there could be duplicate git commits --- app.py | 2 +- database.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 3c002f4..2f38fb6 100755 --- a/app.py +++ b/app.py @@ -70,7 +70,7 @@ def index(): **get_template_items("eden's site :3", db), markdown = parser.parse_text(f.read())[0], featured_thoughts = db.get_featured_thoughts(), - commits = db.get_cached_commits()[:7], + commits = db.get_cached_commits()[:10], sidebar_img = get_sidebar_img(db) ) diff --git a/database.py b/database.py index e68e085..d5327e4 100644 --- a/database.py +++ b/database.py @@ -149,9 +149,9 @@ class Database: threading.Thread(target = update_cache).start() with self.__connection.cursor() as cursor: if since is not None: - cursor.execute("SELECT message, url, commitTime, additions, deletions, total FROM commitCache WHERE commitTime > %s ORDER BY commitTime DESC;", (since, )) + cursor.execute("SELECT DISTINCT message, url, commitTime, additions, deletions, total FROM commitCache WHERE commitTime > %s ORDER BY commitTime DESC;", (since, )) else: - cursor.execute("SELECT message, url, commitTime, additions, deletions, total FROM commitCache ORDER BY commitTime DESC;") + cursor.execute("SELECT DISTINCT message, url, commitTime, additions, deletions, total FROM commitCache ORDER BY commitTime DESC;") # i think i might have spent too long doing functional programming return [{ "repo": urlparse(i[1]).path.split("/")[2], @@ -174,9 +174,10 @@ class Database: def update_commit_cache(self, requested): with self.__connection.cursor() as cursor: - cursor.execute("SELECT DISTINCT url FROM commitCache;") - urls = [i[0] for i in cursor.fetchall()] for commit in requested: + cursor.execute("SELECT DISTINCT url FROM commitCache;") + urls = [i[0] for i in cursor.fetchall()] + if commit["url"] not in urls: cursor.execute(""" INSERT INTO commitCache (message, url, commitTime, additions, deletions, total) @@ -245,7 +246,7 @@ def update_cache(): if __name__ == "__main__": - # update_cache() + update_cache() import json with Database() as db: print(db.get_cached_commits()[0]) -- cgit v1.2.3