Skip to content
Snippets Groups Projects
Commit a4c5e4a6 authored by Erik Johnston's avatar Erik Johnston
Browse files

Fix thumbnailing remote files

parent 1159abbd
No related branches found
No related tags found
No related merge requests found
...@@ -227,6 +227,34 @@ class MediaRepository(object): ...@@ -227,6 +227,34 @@ class MediaRepository(object):
else: else:
respond_404(request) respond_404(request)
@defer.inlineCallbacks
def get_remote_media_info(self, server_name, media_id):
"""Gets the media info associated with the remote file, downloading
if necessary.
Args:
server_name (str): Remote server_name where the media originated.
media_id (str): The media ID of the content (as defined by the
remote server).
Returns:
Deferred[dict]: The media_info of the file
"""
# We linearize here to ensure that we don't try and download remote
# media multiple times concurrently
key = (server_name, media_id)
with (yield self.remote_media_linearizer.queue(key)):
responder, media_info = yield self._get_remote_media_impl(
server_name, media_id,
)
# Ensure we actually use the responder so that it releases resources
if responder:
with responder:
pass
defer.returnValue(media_info)
@defer.inlineCallbacks @defer.inlineCallbacks
def _get_remote_media_impl(self, server_name, media_id): def _get_remote_media_impl(self, server_name, media_id):
"""Looks for media in local cache, if not there then attempt to """Looks for media in local cache, if not there then attempt to
......
...@@ -165,7 +165,7 @@ class ThumbnailResource(Resource): ...@@ -165,7 +165,7 @@ class ThumbnailResource(Resource):
def _select_or_generate_remote_thumbnail(self, request, server_name, media_id, def _select_or_generate_remote_thumbnail(self, request, server_name, media_id,
desired_width, desired_height, desired_width, desired_height,
desired_method, desired_type): desired_method, desired_type):
media_info = yield self.media_repo.get_remote_media(server_name, media_id) media_info = yield self.media_repo.get_remote_media_info(server_name, media_id)
thumbnail_infos = yield self.store.get_remote_media_thumbnails( thumbnail_infos = yield self.store.get_remote_media_thumbnails(
server_name, media_id, server_name, media_id,
...@@ -216,7 +216,7 @@ class ThumbnailResource(Resource): ...@@ -216,7 +216,7 @@ class ThumbnailResource(Resource):
# TODO: Don't download the whole remote file # TODO: Don't download the whole remote file
# We should proxy the thumbnail from the remote server instead of # We should proxy the thumbnail from the remote server instead of
# downloading the remote file and generating our own thumbnails. # downloading the remote file and generating our own thumbnails.
yield self.media_repo.get_remote_media(server_name, media_id) yield self.media_repo.get_remote_media_info(server_name, media_id)
thumbnail_infos = yield self.store.get_remote_media_thumbnails( thumbnail_infos = yield self.store.get_remote_media_thumbnails(
server_name, media_id, server_name, media_id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment