Pre-fetch data from the DB and hand to markdown thread

We want to avoid opening a DB connection in the markdown thread
as its DB connection might live for a long time

(imported from commit 7700b2ca793ee5e9add7f071b92f22a4bf576b3d)
This commit is contained in:
Leo Franchi
2013-10-09 14:48:05 -04:00
parent 62dde61ca4
commit 08ae641dd2
4 changed files with 54 additions and 31 deletions

View File

@@ -9,16 +9,5 @@ find_mentions = r'(?<![^\s\'\"\(,:<])@(?:\*\*([^\*]+)\*\*|(\w+))'
wildcards = ['all', 'everyone']
def find_user_for_mention(mention, realm):
if mention in wildcards:
return (True, None)
try:
user = zerver.models.UserProfile.objects.filter(
Q(full_name__iexact=mention) | Q(short_name__iexact=mention),
is_active=True,
realm=realm).order_by("id")[0]
except IndexError:
user = None
return (False, user)
def user_mention_matches_wildcard(mention):
return mention in wildcards