From 39ff09e777bad5193288b34323d9f6bd4b364fb8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 26 Jul 2023 01:37:54 +0300 Subject: [PATCH] restore bump sort --- files/classes/post.py | 5 ++++- files/helpers/config/const.py | 2 +- files/helpers/sorting_and_time.py | 2 ++ files/routes/comments.py | 1 + files/templates/home.html | 2 ++ migrations/20230723-restore-bump-sort.sql | 9 +++++++++ 6 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 migrations/20230723-restore-bump-sort.sql diff --git a/files/classes/post.py b/files/classes/post.py index 8512b5807..23394f0bc 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -61,6 +61,7 @@ class Post(Base): notify = Column(Boolean) chudded = Column(Boolean, default=False) ping_cost = Column(Integer) + bump_utc = Column(Integer) author = relationship("User", primaryjoin="Post.author_id==User.id") oauth_app = relationship("OauthApp") @@ -72,7 +73,9 @@ class Post(Base): options = relationship("PostOption", order_by="PostOption.id") def __init__(self, *args, **kwargs): - if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + if "created_utc" not in kwargs: + kwargs["created_utc"] = int(time.time()) + kwargs["bump_utc"] = kwargs["created_utc"] super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 89196dca1..35cce1ba9 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -321,7 +321,7 @@ THEMES = ["4chan","classic","classic_dark","coffee","dark","dramblr","light","mi LIGHT_THEMES = ["4chan","classic","coffee","light","win98"] BACKGROUND_CATEGORIES = ["glitter", "anime", "fantasy", "solarpunk", "pixelart"] COMMENT_SORTS = ["hot", "new", "old", "top", "bottom", "controversial", "saves"] -SORTS = COMMENT_SORTS + ["comments", "views", "subscriptions", "saves"] +SORTS = COMMENT_SORTS + ["bump", "comments", "views", "subscriptions", "saves"] TIME_FILTERS = ["hour", "day", "week", "month", "year", "all"] PAGE_SIZES = (10, 25, 50, 100) diff --git a/files/helpers/sorting_and_time.py b/files/helpers/sorting_and_time.py index ab2165849..bc442b86e 100644 --- a/files/helpers/sorting_and_time.py +++ b/files/helpers/sorting_and_time.py @@ -33,6 +33,8 @@ def sort_objects(sort, objects, cls): return objects.order_by(-1000000*(metric + 1)/(func.power(((ti - cls.created_utc)/1000), 1.35)), cls.created_utc.desc()) elif sort == "views" and cls.__name__ == "Post": return objects.order_by(cls.views.desc(), cls.created_utc.desc()) + elif sort == "bump" and cls.__name__ == "Post": + return objects.filter(cls.comment_count > 1).order_by(cls.bump_utc.desc(), cls.created_utc.desc()) elif sort == "comments" and cls.__name__ == "Post": return objects.order_by(cls.comment_count.desc(), cls.created_utc.desc()) elif sort == "subscriptions" and cls.__name__ == "Post": diff --git a/files/routes/comments.py b/files/routes/comments.py index 1e936b878..197cc0ee2 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -387,6 +387,7 @@ def comment(v:User): # Essentially a measure to make comment counts reflect "real" content if (posting_to_post and not rts and not c.slots_result): post_target.comment_count += 1 + post_target.bump_utc = c.created_utc g.db.add(post_target) if c.level > 5: diff --git a/files/templates/home.html b/files/templates/home.html index f0d086e6e..5e0482766 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -106,6 +106,7 @@