0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-09-18 23:58:59 +02:00

Generate local thumbnails on a thread

This commit is contained in:
Erik Johnston 2015-07-23 14:52:29 +01:00
parent 6886bba988
commit 2b4f47db9c

View file

@ -244,6 +244,9 @@ class BaseMediaResource(Resource):
) )
return return
local_thumbnails = []
def generate_thumbnails():
scales = set() scales = set()
crops = set() crops = set()
for r_width, r_height, r_method, r_type in requirements: for r_width, r_height, r_method, r_type in requirements:
@ -262,9 +265,10 @@ class BaseMediaResource(Resource):
) )
self._makedirs(t_path) self._makedirs(t_path)
t_len = thumbnailer.scale(t_path, t_width, t_height, t_type) 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 media_id, t_width, t_height, t_type, t_method, t_len
) ))
for t_width, t_height, t_type in crops: for t_width, t_height, t_type in crops:
if (t_width, t_height, t_type) in scales: if (t_width, t_height, t_type) in scales:
@ -278,9 +282,14 @@ class BaseMediaResource(Resource):
) )
self._makedirs(t_path) self._makedirs(t_path)
t_len = thumbnailer.crop(t_path, t_width, t_height, t_type) 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 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({ defer.returnValue({
"width": m_width, "width": m_width,