diff options
| author | Daniel Schadt <kingdread@gmx.de> | 2025-11-22 19:57:25 +0100 |
|---|---|---|
| committer | Daniel Schadt <kingdread@gmx.de> | 2025-11-22 19:57:25 +0100 |
| commit | 083446efa5163791df235fd70f3f1d38bdd8b832 (patch) | |
| tree | 8c1ebabf7b2fd74a69c2db182fb838252a0b9e63 | |
| parent | 324fc8923b056bf985d4ae49a7de3ac028a89722 (diff) | |
| download | fietsboek-083446efa5163791df235fd70f3f1d38bdd8b832.tar.gz fietsboek-083446efa5163791df235fd70f3f1d38bdd8b832.tar.bz2 fietsboek-083446efa5163791df235fd70f3f1d38bdd8b832.zip | |
don't offer brotli content encoding
That was good while we still had files saved brotli-compressed, but now
it adds more overhead.
| -rw-r--r-- | fietsboek/views/detail.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/fietsboek/views/detail.py b/fietsboek/views/detail.py index 8ca7836..4af7994 100644 --- a/fietsboek/views/detail.py +++ b/fietsboek/views/detail.py @@ -6,7 +6,6 @@ import io import logging from html.parser import HTMLParser -import brotli from markupsafe import Markup from pyramid.httpexceptions import ( HTTPFound, @@ -134,18 +133,17 @@ def gpx(request): wanted_filename = f"{track.id}.gpx" content_disposition = f'attachment; filename="{wanted_filename}"' gpx_data = track.gpx_xml() - # We can be nice to the client if they support it, and deliver the gzipped - # data straight. This saves decompression time on the server and saves a - # lot of bandwidth. - accepted = request.accept_encoding.acceptable_offers(["br", "gzip", "identity"]) + # We used to offer brotli compression here as well, but brotli is too + # inefficient to do on-the-fly. That was only useful while we had the data + # stored brotli-compressed. For comparison, a track with ~50k points: + # identity -- 2.4s -- 5.49 MiB + # gzip -- 2.5s -- 657.53 KiB + # brotli -- 12s -- 389.45 KiB + # So yes, brotli does give better compression than gzip, but the time is + # not worth paying for. + accepted = request.accept_encoding.acceptable_offers(["gzip", "identity"]) for encoding, _qvalue in accepted: - if encoding == "br": - data = brotli.compress(gpx_data) - response = Response(data, content_type="application/gpx+xml", content_encoding="br") - break if encoding == "gzip": - # gzip'ed GPX files are so much smaller than uncompressed ones, it - # is worth re-compressing them for the client data = gzip.compress(gpx_data) response = Response(data, content_type="application/gpx+xml", content_encoding="gzip") break |
