about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/metadata_api/wiki.py3
-rw-r--r--gn3/db/rdf/wiki.py33
2 files changed, 7 insertions, 29 deletions
diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py
index 7595993..bb7d2d2 100644
--- a/gn3/api/metadata_api/wiki.py
+++ b/gn3/api/metadata_api/wiki.py
@@ -48,6 +48,7 @@ def edit_wiki(comment_id: int):
     """
     with db_utils.database_connection(current_app.config["SQL_URI"]) as conn:
         cursor = conn.cursor()
+        next_version = 0
         try:
             category_ids = wiki.get_categories_ids(
                 cursor, payload["categories"])
@@ -76,8 +77,8 @@ def edit_wiki(comment_id: int):
         update_wiki_comment(
             comment_id=comment_id,
             payload=payload,
+            next_version=next_version,
             sparql_conf={
-                "sparql_uri": current_app.config["SPARQL_ENDPOINT"],
                 "sparql_user": current_app.config["SPARQL_USER"],
                 "sparql_password": current_app.config["SPARQL_PASSWORD"],
                 "sparql_auth_uri": current_app.config["SPARQL_AUTH_URI"],
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 ;