bugdown: Lazily import python-twitter.

python-twitter was consuming a significant amount of import time.
However, this commit seems to not save any time at all, probably
because its recursive dependencies are imported elsewhere in Zulip.
This commit is contained in:
Tim Abbott 2018-08-08 09:06:51 -07:00
parent 4d07e485ff
commit 38afeb7ac2
1 changed files with 5 additions and 1 deletions

View File

@ -12,7 +12,6 @@ import urllib
import re
import os
import html
import twitter
import platform
import time
import functools
@ -302,6 +301,11 @@ def fetch_tweet_data(tweet_id: str) -> Optional[Dict[str, Any]]:
if not all(creds.values()):
return None
# We lazily import twitter here because its import process is
# surprisingly slow, and doing so has a significant impact on
# the startup performance of `manage.py` commands.
import twitter
try:
api = twitter.Api(tweet_mode='extended', **creds)
# Sometimes Twitter hangs on responses. Timing out here