Skip to content

Commit

Permalink
Only check the body if the result won't be discarded
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
csnardi committed Jul 3, 2015
1 parent 686ad33 commit 83384a1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions findspam.py
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 83384a1

Please sign in to comment.