Pins: fix infinite recursion

This commit is contained in:
justcool393 2023-02-16 18:46:43 -06:00
parent d728a16a19
commit 31f273ca32
2 changed files with 5 additions and 6 deletions

View file

@ -65,7 +65,7 @@ def sort_objects(objects: Query, sort: str, cls):
# 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: Iterable[Comment], sort:str, **kwargs):
def sort_comment_results(comments: Iterable[Comment], sort:str, *, pins:bool=False):
"""
Sorts comments results from `files.helpers.get.get_comments_trees_eager`
:param comments: Comments to sort
@ -98,8 +98,7 @@ def sort_comment_results(comments: Iterable[Comment], sort:str, **kwargs):
else: # default, or sort == 'new'
key_func = lambda c: -c.created_utc
if kwargs.get('pins', True):
key_func = lambda c: (
key_func_pinned = lambda c: (
(c.is_pinned is None, c.is_pinned == '', c.is_pinned), # sort None last
key_func(c))
return sorted(comments, key=key_func)
return sorted(comments, key=key_func_pinned if pins else key_func)