From 6cfc862d63720f817c8578c8156ec5eec9fb9b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 17 Aug 2025 20:52:19 +0300 Subject: [PATCH] fix subscription unread count calculation --- app/models.py | 7 +++++-- app/routes/topics.py | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index 79e7fdc..3be8a86 100644 --- a/app/models.py +++ b/app/models.py @@ -255,8 +255,11 @@ class Subscriptions(Model): q = """SELECT COUNT(*) AS unread_count FROM posts LEFT JOIN subscriptions ON subscriptions.thread_id = posts.thread_id - WHERE subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen""" - return db.fetch_one(q, self.user_id)['unread_count'] + WHERE subscriptions.user_id = ? AND posts.created_at > subscriptions.last_seen AND posts.thread_id = ?""" + res = db.fetch_one(q, self.user_id, self.thread_id) + if res: + return res['unread_count'] + return None class APIRateLimits(Model): table = 'api_rate_limits' diff --git a/app/routes/topics.py b/app/routes/topics.py index 0cced0e..d1cd0c0 100644 --- a/app/routes/topics.py +++ b/app/routes/topics.py @@ -71,8 +71,7 @@ def topic(slug): 'thread_id': thread['id'], }) if subscription: - print(subscription.get_unread_count()) - subscriptions[subscription.id] = subscription.get_unread_count() + subscriptions[thread['id']] = subscription.get_unread_count() return render_template( "topics/topic.html",