From e77350dc8e06fbae9b1d80b90eba9bdbf85cdfd1 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 12 Mar 2018 14:41:35 -0400 Subject: [PATCH] search refactor: Replace confusing `!= 0` idiom in search code. We want to say `if num_after > 0` when we expect num_after to be a positive integer. We don't want any confusion that we will execute the blocks for values of -7 or None. --- zerver/views/messages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zerver/views/messages.py b/zerver/views/messages.py index a8a41e0ad2..70fa71c5b1 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -633,7 +633,7 @@ def get_messages_backend(request: HttpRequest, user_profile: UserProfile, # specified to ensure that the resulting list always contains the # anchor message. If a narrow was specified, the anchor message # might not match the narrow anyway. - if num_after != 0: + if num_after > 0: num_after += num_extra_messages else: num_before += num_extra_messages @@ -672,14 +672,14 @@ def get_messages_backend(request: HttpRequest, user_profile: UserProfile, before_query = None after_query = None - if num_before != 0: + if num_before > 0: before_anchor = anchor - if num_after != 0: + if num_after > 0: # Don't include the anchor in both the before query and the after query before_anchor = anchor - 1 before_query = query.where(inner_msg_id_col <= before_anchor) \ .order_by(inner_msg_id_col.desc()).limit(num_before) - if num_after != 0: + if num_after > 0: after_query = query.where(inner_msg_id_col >= anchor) \ .order_by(inner_msg_id_col.asc()).limit(num_after)