Merge pull request #207 from matrix-org/erikj/generate_local_thumbnails_on_thread

Generate local thumbnails on a thread
This commit is contained in:
Erik Johnston 2015-07-27 14:57:25 +01:00
commit c472d6107e

View File

@ -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,