From 39a3e9b4688d92a1c5f608d55e26610bc577c9d9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 27 Jul 2023 09:09:28 +0000 Subject: [PATCH] blog: Remove unneeded backend functions Signed-off-by: Michael Tremer --- src/backend/blog.py | 46 +++++---------------------------------------- src/web/blog.py | 2 +- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/src/backend/blog.py b/src/backend/blog.py index a626cb2e..b21c9aa9 100644 --- a/src/backend/blog.py +++ b/src/backend/blog.py @@ -49,14 +49,6 @@ class Blog(misc.Object): AND %s = ANY(tags) \ ORDER BY published_at DESC LIMIT %s", tag, limit) - def get_by_author(self, author, limit=None): - return self._get_posts("SELECT * FROM blog \ - WHERE (author = %s OR author_uid = %s) \ - AND published_at IS NOT NULL \ - AND published_at <= NOW() \ - ORDER BY published_at DESC LIMIT %s", - author.name, author.uid, limit) - def get_by_year(self, year): return self._get_posts("SELECT * FROM blog \ WHERE EXTRACT(year FROM published_at) = %s \ @@ -64,17 +56,12 @@ class Blog(misc.Object): AND published_at <= NOW() \ ORDER BY published_at DESC", year) - def get_drafts(self, author=None, limit=None): - if author: - return self._get_posts("SELECT * FROM blog \ - WHERE author_uid = %s \ - AND (published_at IS NULL OR published_at > NOW()) \ - ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", - author.uid, limit) - + def get_drafts(self, author, limit=None): return self._get_posts("SELECT * FROM blog \ - WHERE (published_at IS NULL OR published_at > NOW()) \ - ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", limit) + WHERE author_uid = %s \ + AND (published_at IS NULL OR published_at > NOW()) \ + ORDER BY COALESCE(updated_at, created_at) DESC LIMIT %s", + author.uid, limit) def search(self, query, limit=None): posts = self._get_posts("SELECT blog.* FROM blog \ @@ -163,29 +150,6 @@ class Blog(misc.Object): for row in res: yield row.year - @property - def authors(self): - res = self.db.query(""" - SELECT - author_uid, - MAX(published_at) AS published_at - FROM - blog - WHERE - author_uid IS NOT NULL - AND - published_at IS NOT NULL - AND - published_at <= NOW() - GROUP BY - author_uid - ORDER BY - published_at DESC - """, - ) - - return [self.backend.accounts.get_by_uid(row.author_uid) for row in res] - async def announce(self): posts = self._get_posts("SELECT * FROM blog \ WHERE (published_at IS NOT NULL AND published_at <= NOW()) \ diff --git a/src/web/blog.py b/src/web/blog.py index 7ff5f060..a2ac1e32 100644 --- a/src/web/blog.py +++ b/src/web/blog.py @@ -238,7 +238,7 @@ class DeleteHandler(base.BaseHandler): class HistoryNavigationModule(ui_modules.UIModule): def render(self): return self.render_string("blog/modules/history-navigation.html", - authors=self.backend.blog.authors, years=self.backend.blog.years) + years=self.backend.blog.years) class ListModule(ui_modules.UIModule): -- 2.47.2