already_sent_mirrored_message: Clean up query

No need for an 'if' if we're just returning a boolean.  And using
QuerySet.exists() should be a little more efficient.

(imported from commit 69ec3cc9f2fe904ec40ea3b8a8687a06cd03f3f3)
This commit is contained in:
Keegan McAllister
2012-11-01 16:06:28 -04:00
parent e94c6fdf86
commit 0fbb33c33f

View File

@@ -497,12 +497,11 @@ def already_sent_mirrored_message(request):
utc_from_ts = datetime.datetime.utcfromtimestamp
req_time = float(request.POST['time'])
email = request.POST['sender'].lower()
if Message.objects.filter(sender__user__email=email,
return Message.objects.filter(
sender__user__email=email,
content=request.POST['content'],
pub_date__gt=utc_from_ts(req_time - 10).replace(tzinfo=utc),
pub_date__lt=utc_from_ts(req_time + 10).replace(tzinfo=utc)):
return True
return False
pub_date__lt=utc_from_ts(req_time + 10).replace(tzinfo=utc)).exists()
# Validte that the passed in object is an email address from the user's realm
# TODO: Check that it's a real email address here.