mirror of
https://github.com/block/buzz.git
synced 2026-11-05 17:01:35 +00:00
fix(db): hydrate SQLite search hits
Signed-off-by: npub13n66s06epmqf2kc3v373ez8hj65cuzyvxzjf93vwpervxqn2u7jq2qd9je <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
This commit is contained in:
committed by
Brother Darryl
parent
1642d7c76a
commit
f07f346e00
@@ -2046,7 +2046,12 @@ impl Db {
|
||||
community_id: CommunityId,
|
||||
ids: &[&[u8]],
|
||||
) -> Result<Vec<StoredEvent>> {
|
||||
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<Vec<StoredEvent>> {
|
||||
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 {
|
||||
|
||||
@@ -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<Vec<buzz_core::StoredEvent>> {
|
||||
if ids.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let mut qb = sqlx::QueryBuilder::<sqlx::Sqlite>::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,
|
||||
|
||||
Reference in New Issue
Block a user