Generate local thumbnails on a thread

pull/4/merge
Erik Johnston 9 years ago
parent 6886bba988
commit 2b4f47db9c
  1. 17
      synapse/rest/media/v1/base_resource.py

@ -244,6 +244,9 @@ class BaseMediaResource(Resource):
)
return
local_thumbnails = []
def generate_thumbnails():
scales = set()
crops = set()
for r_width, r_height, r_method, r_type in requirements:
@ -262,9 +265,10 @@ class BaseMediaResource(Resource):
)
self._makedirs(t_path)
t_len = thumbnailer.scale(t_path, t_width, t_height, t_type)
yield self.store.store_local_thumbnail(
local_thumbnails.append((
media_id, t_width, t_height, t_type, t_method, t_len
)
))
for t_width, t_height, t_type in crops:
if (t_width, t_height, t_type) in scales:
@ -278,9 +282,14 @@ class BaseMediaResource(Resource):
)
self._makedirs(t_path)
t_len = thumbnailer.crop(t_path, t_width, t_height, t_type)
yield self.store.store_local_thumbnail(
local_thumbnails.append((
media_id, t_width, t_height, t_type, t_method, t_len
)
))
yield threads.deferToThread(generate_thumbnails)
for l in local_thumbnails:
yield self.store.store_local_thumbnail(*l)
defer.returnValue({
"width": m_width,

Loading…
Cancel
Save