Skip to content

Commit 36bfdb6

Browse files
committed
only pull frames when doing write delegation
1 parent 361d082 commit 36bfdb6

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

libsql/src/database.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ cfg_replication! {
392392
#[cfg(feature = "replication")]
393393
DbType::Sync { db, encryption_config: _ } => db.sync().await,
394394
#[cfg(feature = "sync")]
395-
DbType::Offline { db, .. } => db.sync_offline().await,
395+
DbType::Offline { db, remote_writes: false, .. } => db.sync_offline().await,
396+
DbType::Offline { db, remote_writes: true, .. } => {
397+
let mut sync_ctx = db.sync_ctx.as_ref().unwrap().lock().await;
398+
crate::sync::bootstrap_db(&mut sync_ctx).await?;
399+
let conn = db.connect()?;
400+
crate::sync::try_pull(&mut sync_ctx, &conn).await
401+
},
396402
_ => Err(Error::SyncNotSupported(format!("{:?}", self.db_type))),
397403
}
398404
}

libsql/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ async fn try_push(
814814
})
815815
}
816816

817-
async fn try_pull(
817+
pub async fn try_pull(
818818
sync_ctx: &mut SyncContext,
819819
conn: &Connection,
820820
) -> Result<crate::database::Replicated> {

libsql/src/sync/statement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ impl Stmt for SyncedStatement {
2222
async fn execute(&mut self, params: &Params) -> Result<usize> {
2323
let result = self.inner.execute(params).await;
2424
let mut context = self.context.lock().await;
25-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
25+
crate::sync::try_pull(&mut context, &self.conn).await?;
2626
result
2727
}
2828

2929
async fn query(&mut self, params: &Params) -> Result<Rows> {
3030
let result = self.inner.query(params).await;
3131
let mut context = self.context.lock().await;
32-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
32+
crate::sync::try_pull(&mut context, &self.conn).await?;
3333
result
3434
}
3535

3636
async fn run(&mut self, params: &Params) -> Result<()> {
3737
let result = self.inner.run(params).await;
3838
let mut context = self.context.lock().await;
39-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
39+
crate::sync::try_pull(&mut context, &self.conn).await?;
4040
result
4141
}
4242

0 commit comments

Comments
 (0)