From 1391a6e0913295518b114a4bc15f201cbc6a3332 Mon Sep 17 00:00:00 2001 From: akarras Date: Sun, 28 Jan 2024 17:17:29 -0700 Subject: [PATCH] lazy load listings retainers --- ultros-db/src/listings.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ultros-db/src/listings.rs b/ultros-db/src/listings.rs index ec8e991a..56ddd531 100644 --- a/ultros-db/src/listings.rs +++ b/ultros-db/src/listings.rs @@ -164,12 +164,25 @@ impl UltrosDb { ) -> Result)>> { use active_listing::*; let instant = Instant::now(); - let query = Entity::find() + let listings = Entity::find() .filter(Column::ItemId.eq(item.0)) .filter(Column::WorldId.eq(world)) - .find_also_related(retainer::Entity) .all(&self.db) .await?; + let retainers = retainer::Entity::find() + .filter(retainer::Column::Id.is_in(listings.iter().map(|l| l.retainer_id).unique())) + .all(&self.db) + .await? + .into_iter() + .map(|r| (r.id, r)) + .collect::>(); + let query = listings + .into_iter() + .map(|l| { + let retainer = retainers.get(&l.retainer_id).cloned(); + (l, retainer) + }) + .collect::>(); histogram!("ultros_db_query_listings_with_retainers_duration_seconds") .record(instant.elapsed()); Ok(query)