diff options
author | Munyoki Kilyungi | 2024-09-17 19:31:59 +0300 |
---|---|---|
committer | John Nduli Kilyungi | 2024-09-18 08:32:34 +0300 |
commit | 1a289eca7d770487d3f87c612a3c76e7fd247f6e (patch) | |
tree | 454275db2f56d6924dcab04adeba4aec8a675ecd /gn3/db | |
parent | 0131996686e8cc34ab698212f2da879af0dea71c (diff) | |
download | genenetwork3-1a289eca7d770487d3f87c612a3c76e7fd247f6e.tar.gz |
Get the next versionId from SQL.
* gn3/api/metadata_api/wiki.py (edit_wiki): Get the next version Id
from SQL
* gn3/db/rdf/wiki.py (get_next_comment_version): Delete.
(update_wiki_comment): Provide the next_version id as an extra arg.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r-- | gn3/db/rdf/wiki.py | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py index 152b261..55f4162 100644 --- a/gn3/db/rdf/wiki.py +++ b/gn3/db/rdf/wiki.py @@ -189,33 +189,12 @@ CONSTRUCT { return results -def get_next_comment_version( - comment_id: int, sparql_uri: str, graph: str = "<http://genenetwork.org>" -) -> int: - "Find the next version to add" - query = Template( - """ -$prefix - -SELECT MAX(?version) as ?max_version FROM $graph WHERE { - ?comment rdf:type gnc:GNWikiEntry ; - dct:identifier "$comment_id"^^xsd:integer ; - dct:hasVersion ?version . -} -""" - ).substitute(prefix=RDF_PREFIXES, graph=graph, comment_id=comment_id) - results = sparql_query( - query=query, endpoint=sparql_uri, format_type="json")[0] - if not results: - raise MissingDBDataException - return int(results["max_version"]["value"]) + 1 - - def update_wiki_comment( - comment_id: int, - payload: dict, - sparql_conf: dict, - graph: str = "<http://genenetwork.org>", + comment_id: int, + payload: dict, + next_version: int, + sparql_conf: dict, + graph: str = "<http://genenetwork.org>", ) -> tuple[str, int]: """Update a wiki comment by inserting a comment with the same identifier but an updated version id. The End form of this query @@ -244,8 +223,6 @@ looks like: } } """ - next_version = get_next_comment_version( - comment_id, sparql_conf['sparql_uri'], graph) name = f"gn:wiki-{comment_id}-{next_version}" comment_triple = Template("""$name rdf:label '''$comment'''@en ; rdf:type gnc:GNWikiEntry ; |