From 90458985115a0cc1234c7e39436d6ee50838b136 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Mon, 9 Sep 2024 22:53:09 +0300 Subject: Move comment on the manual sort to the doc-string. Signed-off-by: Munyoki Kilyungi --- gn3/db/rdf/wiki.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'gn3/db') diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py index f7b0030..f3a56da 100644 --- a/gn3/db/rdf/wiki.py +++ b/gn3/db/rdf/wiki.py @@ -1,5 +1,13 @@ """Sparql queries to get metadata about WIKI and RIF metadata. +NOTE: In the CONSTRUCT queries below, we manually sort the arrays from + the result of a CONSTRUCT. This is because the SPARQL engine does + not provide a guarantee that it will support an ORDER BY clause in a + CONSTRUCT. Using ORDER BY on a solution sequence for a CONSTRUCT or + DESCRIBE query has no direct effect because only SELECT returns a + sequence of results. See: + + """ from string import Template from gn3.db.rdf import (BASE_CONTEXT, RDF_PREFIXES, @@ -104,6 +112,7 @@ CONSTRUCT { ) data = [__sanitize_result(result) for result in results.get("data")] + # See note above in the doc-string results["data"] = sorted(data, key=lambda d: d["created"]) if not data: return results @@ -163,12 +172,6 @@ CONSTRUCT { ) data = [__sanitize_result(result) for result in results.get("data")] - # We manually sort the array, since the SPARQL engine does not - # provide a guarantee that it will support an ORDER BY clause in a - # CONSTRUCT. Using ORDER BY on a solution sequence for a CONSTRUCT - # or DESCRIBE query has no direct effect because only SELECT - # returns a sequence of results. See: - # - # + # See note above in the doc-string results["data"] = sorted(data, key=lambda d: d["version"], reverse=True) return results -- cgit v1.2.3