restore bump sort

pull/173/head
Aevann 2023-07-26 01:37:54 +03:00
parent 6ceb087912
commit 39ff09e777
6 changed files with 19 additions and 2 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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":

View File

@ -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:

View File

@ -106,6 +106,7 @@
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton2" data-bs-toggle="dropdown">
{% if sort=="hot" %}<i class="fas fa-fire mr-1"></i>{% endif %}
{% if sort=="views" %}<i class="fas fa-eye mr-1"></i>{% endif %}
{% if sort=="bump" %}<i class="fas fa-arrow-up mr-1"></i>{% endif %}
{% if sort=="top" %}<i class="fas fa-arrow-alt-circle-up mr-1"></i>{% endif %}
{% if sort=="bottom" %}<i class="fas fa-arrow-alt-circle-down mr-1"></i>{% endif %}
{% if sort=="new" %}<i class="fas fa-sparkles mr-1"></i>{% endif %}
@ -119,6 +120,7 @@
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px;">
{% if sort != "hot" %}<a class="dropdown-item" href="?sort=hot&t={{t}}"><i class="fas fa-fire mr-2"></i>Hot</a>{% endif %}
{% if sort != "views" %}<a class="dropdown-item" href="?sort=views&t={{t}}"><i class="fas fa-eye mr-2"></i>Views</a>{% endif %}
{% if sort != "bump" %}<a class="dropdown-item" href="?sort=bump&t={{t}}"><i class="fas fa-arrow-up mr-2"></i>Bump</a>{% endif %}
{% if sort != "top" %}<a class="dropdown-item" href="?sort=top&t={{t}}"><i class="fas fa-arrow-alt-circle-up mr-2"></i>Top</a>{% endif %}
{% if sort != "bottom" %}<a class="dropdown-item" href="?sort=bottom&t={{t}}"><i class="fas fa-arrow-alt-circle-down mr-2"></i>Bottom</a>{% endif %}
{% if sort != "new" %}<a class="dropdown-item" href="?sort=new&t={{t}}"><i class="fas fa-sparkles mr-2"></i>New</a>{% endif %}

View File

@ -0,0 +1,9 @@
alter table posts add column bump_utc integer default 0 not null;
alter table posts alter column bump_utc drop default;
update posts set bump_utc=(SELECT CREATED_UTC FROM comments WHERE comments.created_utc is not null and parent_post = posts.id ORDER BY created_utc desc LIMIT 1) where comment_count>1;
update posts set bump_utc=created_utc where bump_utc=0;
CREATE INDEX posts_bump_utc_idx ON public.posts USING btree (bump_utc);