From f07f346e0095ad735d1acb8cff395c791adeb0eb Mon Sep 17 00:00:00 2001 From: npub13n66s06epmqf2kc3v373ez8hj65cuzyvxzjf93vwpervxqn2u7jq2qd9je <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz> Date: Sat, 1 Aug 2026 14:29:26 -0400 Subject: [PATCH] fix(db): hydrate SQLite search hits Signed-off-by: npub13n66s06epmqf2kc3v373ez8hj65cuzyvxzjf93vwpervxqn2u7jq2qd9je <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz> --- crates/buzz-db/src/lib.rs | 10 +++++++++- crates/buzz-db/src/sqlite.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/buzz-db/src/lib.rs b/crates/buzz-db/src/lib.rs index 08bb3fffb2..3fe9aca050 100644 --- a/crates/buzz-db/src/lib.rs +++ b/crates/buzz-db/src/lib.rs @@ -2046,7 +2046,12 @@ impl Db { community_id: CommunityId, ids: &[&[u8]], ) -> Result> { - event::get_events_by_ids(self.pg_pool()?, community_id, ids).await + match &self.backend { + DbBackend::SQLite(pool) => sqlite::get_events_by_ids(pool, community_id, ids).await, + DbBackend::Postgres => { + event::get_events_by_ids(self.pg_pool()?, community_id, ids).await + } + } } /// [`Db::get_events_by_ids`] with replica routing — same contract and @@ -2062,6 +2067,9 @@ impl Db { community_id: CommunityId, ids: &[&[u8]], ) -> Result> { + if let DbBackend::SQLite(pool) = &self.backend { + return sqlite::get_events_by_ids(pool, community_id, ids).await; + } match self.route_read(path, RoutePredicate::Bounded).await { RouteDecision::Replica(mut tx, _entry, reason) => { match event::get_events_by_ids_on(&mut tx, community_id, ids).await { diff --git a/crates/buzz-db/src/sqlite.rs b/crates/buzz-db/src/sqlite.rs index 3566fdd3a2..7d36580491 100644 --- a/crates/buzz-db/src/sqlite.rs +++ b/crates/buzz-db/src/sqlite.rs @@ -876,6 +876,32 @@ pub(crate) async fn get_event_by_id( row.map(stored_event).transpose() } +pub(crate) async fn get_events_by_ids( + pool: &SqlitePool, + community: CommunityId, + ids: &[&[u8]], +) -> Result> { + if ids.is_empty() { + return Ok(Vec::new()); + } + let mut qb = sqlx::QueryBuilder::::new( + "SELECT event_json, received_at, channel_id FROM events WHERE community_id = ", + ); + qb.push_bind(community.as_uuid().to_string()); + qb.push(" AND id IN ("); + let mut separated = qb.separated(", "); + for id in ids { + separated.push_bind(*id); + } + separated.push_unseparated(")"); + qb.build() + .fetch_all(pool) + .await? + .into_iter() + .map(stored_event) + .collect() +} + pub(crate) async fn query_events( pool: &SqlitePool, q: &crate::EventQuery,