about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wikidata.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/wikidata.rs b/src/wikidata.rs
index 2a69ddb..f5f75a2 100644
--- a/src/wikidata.rs
+++ b/src/wikidata.rs
@@ -226,10 +226,16 @@ fn fetch(
     })
 }
 
+/// How long one SPARQL call may take. Wikidata's query service answers in
+/// one to three seconds usually, but is a shared public service and has been
+/// measured at nine; two queries in a row need the room, and only the first
+/// call for a symbol pays it (the answer is cached for a week).
+const SPARQL_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
+
 /// `POST query=…` to a SPARQL endpoint, asking for SPARQL JSON.
 fn sparql(endpoint: &str, query: &str) -> Result<serde_json::Value, WikidataError> {
     let agent = ureq::Agent::config_builder()
-        .timeout_global(Some(std::time::Duration::from_secs(20)))
+        .timeout_global(Some(SPARQL_TIMEOUT))
         .build()
         .new_agent();
     let response = agent
@@ -237,7 +243,12 @@ fn sparql(endpoint: &str, query: &str) -> Result<serde_json::Value, WikidataErro
         .header("Accept", "application/sparql-results+json")
         .header("User-Agent", "genenetwork4 (+https://genenetwork.org)")
         .send_form([("query", query)])
-        .map_err(|error| WikidataError::Unavailable(format!("{endpoint}: {error}")))?;
+        .map_err(|error| {
+            WikidataError::Unavailable(format!(
+                "{endpoint}: {error} (gave up after {}s)",
+                SPARQL_TIMEOUT.as_secs()
+            ))
+        })?;
     response
         .into_body()
         .read_json::<serde_json::Value>()