thrimshim: Fix performance issue with getting template png

Bytes returned from the database are a "memoryview" and not a bytes object.
These mostly behave the same, but one difference is that Flask recognizes
a bytes object as something it can send as-is, whereas a memoryview ends up using
its generic "iterable" processing. This results in sending every individual byte of the result
as a single part of a HTTP chunked encoding response, adding 5 bytes and a syscall to every byte returned.

The solution is to explicitly convert it to bytes before returning.
pull/471/head
Mike Lang 3 weeks ago committed by Mike Lang
parent 653f651491
commit 861a426395

@ -628,7 +628,7 @@ def get_template(name):
image = row[0] image = row[0]
logging.info('Thumbnail image of {} fetched'.format(name)) logging.info('Thumbnail image of {} fetched'.format(name))
return flask.Response(image, mimetype='image/png') return flask.Response(bytes(image), mimetype='image/png')
@app.route('/thrimshim/template-metadata/<name>') @app.route('/thrimshim/template-metadata/<name>')

Loading…
Cancel
Save