From 4ff2b19fd9b06f49cb5d4709955230afc0423476 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 14 Aug 2025 15:06:33 +0200 Subject: CGI: Use PostgreSQL 17's json_serialize() function. To avoid JSON-encoding on the Python side. --- webmap-cgi | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'webmap-cgi') diff --git a/webmap-cgi b/webmap-cgi index b5e5f98..3196943 100755 --- a/webmap-cgi +++ b/webmap-cgi @@ -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 -- cgit v1.2.3