Skip to content

Add a with_zone option on ListProcessElements

Erwan Rouchet requested to merge list-process-elements-with-zone into master

Closes #684 (closed)

The SQL queries take 5 to 10 ms with with_zone=False and 40ms with with_zone=True, with the page size not having any influence on the queries. In total, the endpoint takes 210-230ms to output 1000 elements without image info, and 240-260ms to output 1000 elements with image info. In HTML mode (when opening the endpoint in the browser), the endpoint takes 400 to 460ms instead as it has to do some more syntax highlighting.

The get_object_or_404 call to retrieve the DataImport in get_queryset has been moved to a cached property, as it sometimes caused duplicate queries to be made with the HTML output.

Image URL

The image URL is normally retrieved in other lists by calling the image.url property, which in turns calls image.server.build_url(image.path). This would require removing values() and using regular Image instances, which can make the endpoint twice as slow, so I made a URL using database functions.

I concatenated the server's URL with the image path. Since the server's URL might not always include slashes, I added a slash in between, and to avoid duplicate slashes, I trimmed the trailing slashes from the server's URL. PostgreSQL allows trimming any character using RTRIM(url, '/'), the equivalent of url.rstrip('/'); but Django only allows trimming spaces (RTRIM(url) alone), so I added a RTrimChr function to provide that.

When the element has no image, this causes the URL to be /, because NULL is just ignored in concatenations. I added a NullIf clause to just have the query return NULL, which returns None in the serializer without doing any further Python processing.

Edited by Erwan Rouchet

Merge request reports

Loading