diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2025-08-14 15:06:33 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2025-08-14 15:16:32 +0200 |
commit | 4ff2b19fd9b06f49cb5d4709955230afc0423476 (patch) | |
tree | c2a29196df1798bc0fb4173bd6999fa363ce7296 /webmap-cgi | |
parent | 35b84d8af9a0d03434a05e25989fe0e8b7ad1901 (diff) |
CGI: Use PostgreSQL 17's json_serialize() function.
To avoid JSON-encoding on the Python side.
Diffstat (limited to 'webmap-cgi')
-rwxr-xr-x | webmap-cgi | 9 |
1 files changed, 3 insertions, 6 deletions
@@ -23,7 +23,7 @@ import sys from os import path as os_path -from json import load as json_load, dumps as json_dumps, JSONDecodeError +from json import load as json_load, JSONDecodeError import logging from typing import Final, Iterator import atexit @@ -163,10 +163,7 @@ def get_query_map(layernames : set[str]) -> dict[str,bytes]: query += common.escape_identifier(layername) + ' m ' query += 'WHERE m.' + common.escape_identifier(pkey_col) + ' = %s' query += ') ' - # TODO[trixie] use json_serialize() from PostgreSQL 17 to avoid serializing on - # the Python side. (There is also row_to_json() which might be of interest if - # json not jsonb is needed.) - query += 'SELECT to_jsonb(feature) FROM feature' + query += 'SELECT json_serialize(to_json(feature) RETURNING bytea) FROM feature' # The query never returns more than one row since we filter on a single FID. # TODO: batch queries using ANY[] or an IN set (the # consummer will then need # to re-order the response) @@ -237,7 +234,7 @@ def application(env, start_response) -> Iterator[bytes]: first = False else: yield b',' - yield json_dumps(resp[0], ensure_ascii=False, separators=(',', ':')).encode('utf-8') + yield resp[0] # the query never returns more than one row since we filter on a single FID if first: yield b'[]' # no match, empty response |