aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-09-09 22:53:09 +0300
committerBonfaceKilz2024-09-11 10:30:57 +0300
commit90458985115a0cc1234c7e39436d6ee50838b136 (patch)
tree16f273eeea8fc338eaabe9789a24f6e1cffab29f /gn3/db
parent8088292c3fc1669f5a8b2dc2a78180cf0be380cd (diff)
downloadgenenetwork3-90458985115a0cc1234c7e39436d6ee50838b136.tar.gz
Move comment on the manual sort to the doc-string.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/rdf/wiki.py17
1 files changed, 10 insertions, 7 deletions
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:
+ <https://stackoverflow.com/questions/78186393>
+ <https://www.w3.org/TR/rdf-sparql-query/#modOrderBy>
"""
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:
- # <https://stackoverflow.com/questions/78186393>
- # <https://www.w3.org/TR/rdf-sparql-query/#modOrderBy>
+ # See note above in the doc-string
results["data"] = sorted(data, key=lambda d: d["version"], reverse=True)
return results