From fccaaca07f37f995c0502bcdb85f22b952a2fcfc Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 12 Apr 2025 21:14:32 +0100 Subject: [PATCH] More efficient detection of non-empty lists --- bookmarks.py | 8 +++----- cache.py | 2 +- fitnessFunctions.py | 2 +- inbox.py | 2 +- posts.py | 2 +- reaction.py | 3 +-- speaker.py | 9 ++++----- 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/bookmarks.py b/bookmarks.py index 73dcdc7aa..a573be494 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -303,8 +303,7 @@ def bookmark_post(recent_posts_cache: {}, 'object': object_url } if cc_list: - if len(cc_list) > 0: - new_bookmark_json['cc'] = cc_list + new_bookmark_json['cc'] = cc_list # Extract the domain and nickname from a statuses link bookmarked_post_nickname = None @@ -364,9 +363,8 @@ def undo_bookmark_post(recent_posts_cache: {}, } } if cc_list: - if len(cc_list) > 0: - new_undo_bookmark_json['cc'] = cc_list - new_undo_bookmark_json['object']['cc'] = cc_list + new_undo_bookmark_json['cc'] = cc_list + new_undo_bookmark_json['object']['cc'] = cc_list # Extract the domain and nickname from a statuses link bookmarked_post_nickname = None diff --git a/cache.py b/cache.py index fdbc11467..4fedcd36f 100644 --- a/cache.py +++ b/cache.py @@ -154,7 +154,7 @@ def expire_person_cache(person_cache: {}): days_since_cached = (curr_time - cache_time).days if days_since_cached > 2: removals.append(person_url) - if len(removals) > 0: + if removals: for person_url in removals: del person_cache[person_url] print(str(len(removals)) + ' actors were expired from the cache') diff --git a/fitnessFunctions.py b/fitnessFunctions.py index 6a085962f..f881e6aa2 100644 --- a/fitnessFunctions.py +++ b/fitnessFunctions.py @@ -97,7 +97,7 @@ def html_watch_points_graph(base_dir: str, fitness: {}, fitness_id: str, # get the maximum time max_average_time = float(1) - if len(watch_points_list) > 0: + if watch_points_list: max_average_time = float(watch_points_list[0].split(' ')[0]) for watch_point in watch_points_list: average_time = float(watch_point.split(' ')[0]) diff --git a/inbox.py b/inbox.py index 82253611c..132cf44e3 100644 --- a/inbox.py +++ b/inbox.py @@ -3800,7 +3800,7 @@ def run_inbox_queue(server, # Copy any posts addressed to followers into the shared inbox # this avoid copying file multiple times to potentially many # individual inboxes - if len(recipients_dict_followers) > 0: + if len(recipients_dict_followers.items()) > 0: shared_inbox_post_filename = \ queue_json['destination'].replace(inbox_handle, inbox_handle) if not os.path.isfile(shared_inbox_post_filename): diff --git a/posts.py b/posts.py index cd6d33a00..69037225a 100644 --- a/posts.py +++ b/posts.py @@ -4606,7 +4606,7 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int, return box_header page_lines: list[str] = [] - if len(lines) > 0: + if lines: end_line_number = \ len(lines) - 1 - int(items_per_page * page_number) end_line_number = max(end_line_number, 0) diff --git a/reaction.py b/reaction.py index fdc254dc2..c31b7d7dd 100644 --- a/reaction.py +++ b/reaction.py @@ -103,8 +103,7 @@ def _reactionpost(recent_posts_cache: {}, 'content': emoji_content } if cc_list: - if len(cc_list) > 0: - new_reaction_json['cc'] = cc_list + new_reaction_json['cc'] = cc_list # Extract the domain and nickname from a statuses link reaction_post_nickname = None diff --git a/speaker.py b/speaker.py index 59814f430..2736cd3b5 100644 --- a/speaker.py +++ b/speaker.py @@ -545,11 +545,10 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str, print('EX: _post_to_speaker_json unable to read ' + approve_follows_filename) if follows: - if len(follows) > 0: - follow_requests_exist = True - for i, _ in enumerate(follows): - follows[i] = follows[i].strip() - follow_requests_list = follows + follow_requests_exist = True + for i, _ in enumerate(follows): + follows[i] = follows[i].strip() + follow_requests_list = follows post_dm = False dm_filename = accounts_dir + '/.newDM' if os.path.isfile(dm_filename):