diff --git a/Cargo.lock b/Cargo.lock index 954b5b7..700a713 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,9 +292,9 @@ dependencies = [ [[package]] name = "async-h1" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9e2a9745d9cd0d92ed7641ce4d07568985762f92633260f0afe8ac7917d9d7" +checksum = "cc5142de15b549749cce62923a50714b0d7b77f5090ced141599e78899865451" dependencies = [ "async-channel", "async-dup", diff --git a/services/reldata/src/main.rs b/services/reldata/src/main.rs index 0e0c64a..f97d955 100644 --- a/services/reldata/src/main.rs +++ b/services/reldata/src/main.rs @@ -97,15 +97,27 @@ impl Loader for ProjectLoader { type Error = FieldError; async fn load(&self, keys: &[Uuid]) -> Result, Self::Error> { + use std::str::FromStr; + use sqlx::Row; + let uuids = keys.iter().map(|u| u.to_string()).collect::>(); - Ok( - sqlx::query_as::("SELECT * FROM projects WHERE uuid IN (?)") - .bind(&uuids.join(",")) - .fetch(&self.0) - .map_ok(|p: Project| (p.uuid, p)) - .try_collect() - .await?, - ) + // Doing awful things to allow the bulk query with the Uuid since sqlx cannot map a + // hyphenated string back out to a normal Uuid + let mut records = sqlx::query("SELECT * FROM projects WHERE uuid IN ($1)") + .bind(uuids.join(",")) + .fetch(&self.0); + + let mut out = HashMap::new(); + while let Some(row) = records.try_next().await? { + let project = Project { + uuid: Uuid::from_str(row.get("uuid"))?, + title: row.get("title"), + path: row.get("path"), + }; + out.insert(project.uuid, project); + } + + Ok(out) } }