From 3b2438338307e91d39117d7ea13592036163ff9d Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Sun, 16 Jun 2024 18:54:45 +0000 Subject: [PATCH] chore: cache mm-config-version-get (#913) ## Changes --- svc/pkg/mm-config/ops/version-get/src/lib.rs | 30 ++++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/svc/pkg/mm-config/ops/version-get/src/lib.rs b/svc/pkg/mm-config/ops/version-get/src/lib.rs index 0333173edc..6ef0ea6031 100644 --- a/svc/pkg/mm-config/ops/version-get/src/lib.rs +++ b/svc/pkg/mm-config/ops/version-get/src/lib.rs @@ -53,12 +53,6 @@ async fn handle( .map(common::Uuid::as_uuid) .collect::>(); - let versions = fetch_versions(&ctx.base(), req_version_ids) - .await? - .into_iter() - .map(|x| x.1) - .collect::>(); - // TODO: There's a bug with this that returns the lobby groups for the wrong // version, can't figure this out // let versions = ctx @@ -83,6 +77,30 @@ async fn handle( // }) // .await?; + // HACK: Because fetch all doesn't work, we'll use fetch one + let mut versions = Vec::new(); + for version_id in req_version_ids { + let version = ctx + .cache() + .immutable() + .fetch_one_proto("versions2", version_id, |mut cache, req_version_id| { + let ctx = ctx.base(); + + async move { + let versions = fetch_versions(&ctx.base(), vec![req_version_id]).await?; + ensure!(versions.len() <= 1, "too many versions"); + if let Some((_, version)) = versions.into_iter().next() { + cache.resolve(&version_id, version); + } + + Ok(cache) + } + }) + .await?; + if let Some(version) = version { + versions.push(version); + } + } Ok(mm_config::version_get::Response { versions }) }