Kill Embed.ly integration.

(imported from commit dfe42a26e57100108c3c50298041bd520e0d8b1b)
This commit is contained in:
David Roe 2015-08-20 18:15:12 -07:00 committed by Tim Abbott
parent 95afea9006
commit 13f3b448e5
4 changed files with 1 additions and 100 deletions

View File

@ -320,8 +320,6 @@
3 "Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)"
4 "Mozilla/5.0 (compatible; Butterfly/1.0; +http://labs.topsy.com/butterfly/) Gecko/2009032608 Firefox/3.0.8"
9 "Mozilla/5.0 (compatible; CompSpyBot/1.0; +http://www.compspy.com/spider.html)"
13 "Mozilla/5.0 (compatible; Embedly/0.2; +http://support.embed.ly/)"
44 "Mozilla/5.0 (compatible; Embedly/0.2; snap; +http://support.embed.ly/)"
2 "Mozilla/5.0 (compatible; Exabot/3.0; +http://www.exabot.com/go/robot)"
27 "Mozilla/5.0 (compatible; Ezooms/1.0; ezooms.bot@gmail.com)"
2 "Mozilla/5.0 (compatible; FlipboardProxy/1.1; +http://flipboard.com/browserproxy)"

View File

@ -35,10 +35,6 @@ import zerver.lib.alert_words as alert_words
import zerver.lib.mention as mention
if settings.USING_EMBEDLY:
from embedly import Embedly
embedly_client = Embedly(settings.EMBEDLY_KEY, timeout=2.5)
# Format version of the bugdown rendering; stored along with rendered
# messages so that we can efficiently determine what needs to be re-rendered
version = 1
@ -95,9 +91,6 @@ def add_a(root, url, link, height="", title=None, desc=None,
desc_div = markdown.util.etree.SubElement(summary_div, "desc")
desc_div.set("class", "message_inline_image_desc")
def hash_embedly_url(link):
return 'embedly:' + hashlib.sha1(link).hexdigest()
@cache_with_key(lambda tweet_id: tweet_id, cache_name="database", with_statsd_key="tweet_data")
def fetch_tweet_data(tweet_id):
if settings.TEST_SUITE:
@ -479,76 +472,6 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
logging.warning(traceback.format_exc())
return None
def do_embedly(self, root, supported_urls):
# embed.ly support is disabled until it can be
# properly debugged.
#
# We're not deleting the code for now, since we expect to
# restore it and want to be able to update it along with
# future refactorings rather than keeping it as a separate
# branch.
if not settings.USING_EMBEDLY:
return
# We want this to be able to easily reverse the hashing later
keys_to_links = dict((hash_embedly_url(link), link) for link in supported_urls)
cache_hits = cache_get_many(keys_to_links.keys(), cache_name="database")
# Construct a dict of url => oembed_data pairs
oembeds = dict((keys_to_links[key], cache_hits[key]) for key in cache_hits)
to_process = [url for url in supported_urls if not url in oembeds]
to_cache = {}
if to_process:
# Don't touch embed.ly if we have everything cached.
try:
responses = embedly_client.oembed(to_process, maxwidth=250)
except httplib2.socket.timeout:
# We put this in its own try-except because it requires external
# connectivity. If embedly flakes out, we don't want to not-render
# the entire message; we just want to not show the embedly preview.
logging.warning("Embedly Embed timeout for URLs: %s" % (" ".join(to_process)))
logging.warning(traceback.format_exc())
return root
except Exception:
# If things break for any other reason, don't make things sad.
logging.warning(traceback.format_exc())
return root
for oembed_data in responses:
# Don't cache permanent errors
if oembed_data["type"] == "error" and \
oembed_data["error_code"] in (500, 501, 503):
continue
# Convert to dict because otherwise pickling won't work.
to_cache[oembed_data["original_url"]] = dict(oembed_data)
# Cache the newly collected data to the database
cache_set_many(dict((hash_embedly_url(link), to_cache[link]) for link in to_cache),
cache_name="database")
oembeds.update(to_cache)
# Now let's process the URLs in order
for link in supported_urls:
oembed_data = oembeds[link]
if oembed_data["type"] in ("link"):
continue
elif oembed_data["type"] in ("video", "rich") and "script" not in oembed_data["html"]:
placeholder = self.markdown.htmlStash.store(oembed_data["html"], safe=True)
el = markdown.util.etree.SubElement(root, "p")
el.text = placeholder
else:
try:
add_a(root,
oembed_data["thumbnail_url"],
link,
height=oembed_data["thumbnail_height"])
except KeyError:
# We didn't have a thumbnail, so let's just bail and keep on going...
continue
return root
def run(self, root):
# Get all URLs from the blob
found_urls = walk_tree(root, lambda e: e.get("href") if e.tag == "a" else None)
@ -558,7 +481,6 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
return
rendered_tweet_count = 0
embedly_urls = []
for url in found_urls:
dropbox_image = self.dropbox_image(url)
@ -589,19 +511,11 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
div.set("class", "inline-preview-twitter")
div.insert(0, twitter_data)
continue
if settings.USING_EMBEDLY:
if embedly_client.is_supported(url):
embedly_urls.append(url)
continue
# NOTE: settings.USING_EMBEDLY will prevent the below from running
youtube = self.youtube_image(url)
if youtube is not None:
add_a(root, youtube, url)
continue
if settings.USING_EMBEDLY:
self.do_embedly(root, embedly_urls)
class Avatar(markdown.inlinepatterns.Pattern):
def handleMatch(self, match):
img = markdown.util.etree.Element('img')

View File

@ -178,10 +178,7 @@ class BugdownTest(TestCase):
msg = 'Check out the debate: http://www.youtube.com/watch?v=hx1mjT73xYE'
converted = bugdown_convert(msg)
if settings.USING_EMBEDLY:
self.assertEqual(converted, '<p>Check out the debate: <a href="http://www.youtube.com/watch?v=hx1mjT73xYE" target="_blank" title="http://www.youtube.com/watch?v=hx1mjT73xYE">http://www.youtube.com/watch?v=hx1mjT73xYE</a></p>\n<iframe width="250" height="141" src="http://www.youtube.com/embed/hx1mjT73xYE?feature=oembed" frameborder="0" allowfullscreen></iframe>')
else:
self.assertEqual(converted, '<p>Check out the debate: <a href="http://www.youtube.com/watch?v=hx1mjT73xYE" target="_blank" title="http://www.youtube.com/watch?v=hx1mjT73xYE">http://www.youtube.com/watch?v=hx1mjT73xYE</a></p>\n<div class="message_inline_image"><a href="http://www.youtube.com/watch?v=hx1mjT73xYE" target="_blank" title="http://www.youtube.com/watch?v=hx1mjT73xYE"><img src="https://i.ytimg.com/vi/hx1mjT73xYE/default.jpg"></a></div>')
self.assertEqual(converted, '<p>Check out the debate: <a href="http://www.youtube.com/watch?v=hx1mjT73xYE" target="_blank" title="http://www.youtube.com/watch?v=hx1mjT73xYE">http://www.youtube.com/watch?v=hx1mjT73xYE</a></p>\n<div class="message_inline_image"><a href="http://www.youtube.com/watch?v=hx1mjT73xYE" target="_blank" title="http://www.youtube.com/watch?v=hx1mjT73xYE"><img src="https://i.ytimg.com/vi/hx1mjT73xYE/default.jpg"></a></div>')
def test_inline_dropbox(self):
return # The dropbox url format changed

View File

@ -356,7 +356,6 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '',
'TWITTER_CONSUMER_SECRET': '',
'TWITTER_ACCESS_TOKEN_KEY': '',
'TWITTER_ACCESS_TOKEN_SECRET': '',
'EMBEDLY_KEY': '',
'EMAIL_GATEWAY_PATTERN': '',
'EMAIL_GATEWAY_EXAMPLE': '',
'EMAIL_GATEWAY_BOT': None,
@ -915,13 +914,6 @@ if DEPLOYED:
# Filter out user data
DEFAULT_EXCEPTION_REPORTER_FILTER = 'zerver.filters.ZulipExceptionReporterFilter'
# We are not currently using embedly due to some performance issues, but
# we are keeping the code on master for now, behind this launch flag.
# If you turn this back on for dev, you will want it to be still False
# for running the tests, or you will need to ensure that embedly_client.is_supported()
# gets called before the tests run.
USING_EMBEDLY = False
# This is a debugging option only
PROFILE_ALL_REQUESTS = False