From 83384a18e45fa4b913ad4601e7ce89cd0ef69c7c Mon Sep 17 00:00:00 2001 From: hichris1234 Date: Fri, 3 Jul 2015 13:32:08 -0400 Subject: [PATCH] Only check the body if the result won't be discarded If the rule doesn't want body summaries, then we just discard the result. This'll speed up every websocket check_if_spam request from probably 0.3 seconds to ~0.007 (the second number is an actual average). --- findspam.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/findspam.py b/findspam.py index 0486d8098e..dcc55d133d 100644 --- a/findspam.py +++ b/findspam.py @@ -176,7 +176,9 @@ def test_post(title, body, user_name, site, is_answer, body_is_summary): compiled_regex = regex.compile(rule['regex'], regex.UNICODE) matched_title = compiled_regex.findall(title) matched_username = compiled_regex.findall(user_name) - matched_body = compiled_regex.findall(body_to_check) + matched_body = None + if not body_is_summary or rule['body_summary']: + matched_body = compiled_regex.findall(body_to_check) if matched_title and rule['title']: try: if getattr(FindSpam, "%s" % rule['validation_method'])(matched_title): @@ -189,7 +191,7 @@ def test_post(title, body, user_name, site, is_answer, body_is_summary): result.append(rule['reason'].replace("{}", "username")) except KeyError: # There is no special logic for this rule result.append(rule['reason'].replace("{}", "username")) - if matched_body and rule['body'] and (not body_is_summary or rule['body_summary']): + if matched_body and rule['body']: type_of_post = "answer" if is_answer else "body" try: if getattr(FindSpam, "%s" % rule['validation_method'])(matched_body):