Remove unnecessary DESC constant

This commit is contained in:
justcool393 2023-02-16 18:02:26 -06:00
parent 5f73302b28
commit 9ba4f1a8af

View file

@ -1,4 +1,5 @@
import time
from collections.abc import Iterable
from typing import Union
from sqlalchemy.sql import func
@ -62,33 +63,32 @@ def sort_objects(objects: Query, sort: str, cls: type[Union[Comment, Submission]
# Presently designed around files.helpers.get.get_comment_trees_eager
# Behavior should parallel that of sort_objects above. TODO: Unify someday?
def sort_comment_results(comments, sort):
DESC = (2 << 30) - 1 # descending sorts, Y2038 problem, change before then
def sort_comment_results(comments: Iterable[Comment], sort:str):
if sort == 'hot':
ti = int(time.time()) + 3600
key_func = lambda c: (
-100000
* (c.upvotes + 1)
/ (pow(((ti - c.created_utc) / 1000), 1.23)),
DESC - c.created_utc
-c.created_utc
)
elif sort == 'comments':
key_func = lambda c: DESC - c.descendant_count
key_func = lambda c: -c.descendant_count
elif sort == 'controversial':
key_func = lambda c: (
(c.upvotes + 1) / (c.downvotes + 1)
+ (c.downvotes + 1) / (c.upvotes + 1),
DESC - c.downvotes,
DESC - c.created_utc
-c.downvotes,
-c.created_utc
)
elif sort == 'top':
key_func = lambda c: (c.downvotes - c.upvotes, DESC - c.created_utc)
key_func = lambda c: (c.downvotes - c.upvotes, -c.created_utc)
elif sort == 'bottom':
key_func = lambda c: (c.upvotes - c.downvotes, DESC - c.created_utc)
key_func = lambda c: (c.upvotes - c.downvotes, -c.created_utc)
elif sort == 'old':
key_func = lambda c: c.created_utc
else: # default, or sort == 'new'
key_func = lambda c: DESC - c.created_utc
key_func = lambda c: -c.created_utc
key_func_pinned = lambda c: (
(c.is_pinned is None, c.is_pinned == '', c.is_pinned), # sort None last