From 527d0cb1f3ef3b3607e5a516c7e4e82d98e77321 Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Mon, 15 Sep 2025 10:56:13 +0400 Subject: [PATCH] expose revision in the stats method --- bindings/javascript/sync/src/generator.rs | 1 + bindings/javascript/sync/src/lib.rs | 13 +++++++------ sync/engine/src/database_sync_engine.rs | 19 ++++++++++++------- sync/engine/src/types.rs | 1 + 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bindings/javascript/sync/src/generator.rs b/bindings/javascript/sync/src/generator.rs index 141dec016..2aae4f373 100644 --- a/bindings/javascript/sync/src/generator.rs +++ b/bindings/javascript/sync/src/generator.rs @@ -45,6 +45,7 @@ pub enum GeneratorResponse { revert_wal: i64, last_pull_unix_time: i64, last_push_unix_time: Option, + revision: Option, }, } diff --git a/bindings/javascript/sync/src/lib.rs b/bindings/javascript/sync/src/lib.rs index fd4d88e78..e92603508 100644 --- a/bindings/javascript/sync/src/lib.rs +++ b/bindings/javascript/sync/src/lib.rs @@ -269,13 +269,14 @@ impl SyncEngine { self.run(async move |coro, sync_engine| { let sync_engine = try_read(sync_engine)?; let sync_engine = try_unwrap(&sync_engine)?; - let changes = sync_engine.stats(coro).await?; + let stats = sync_engine.stats(coro).await?; Ok(Some(GeneratorResponse::SyncEngineStats { - operations: changes.cdc_operations, - main_wal: changes.main_wal_size as i64, - revert_wal: changes.revert_wal_size as i64, - last_pull_unix_time: changes.last_pull_unix_time, - last_push_unix_time: changes.last_push_unix_time, + operations: stats.cdc_operations, + main_wal: stats.main_wal_size as i64, + revert_wal: stats.revert_wal_size as i64, + last_pull_unix_time: stats.last_pull_unix_time, + last_push_unix_time: stats.last_push_unix_time, + revision: stats.revision, })) }) } diff --git a/sync/engine/src/database_sync_engine.rs b/sync/engine/src/database_sync_engine.rs index 488776aad..6ee1aa174 100644 --- a/sync/engine/src/database_sync_engine.rs +++ b/sync/engine/src/database_sync_engine.rs @@ -138,8 +138,7 @@ impl DatabaseSyncEngine

{ db_file.clone(), OpenFlags::Create, turso_core::DatabaseOpts::new().with_indexes(true), - ) - .unwrap(); + )?; let tape_opts = DatabaseTapeOpts { cdc_table: None, cdc_mode: Some("full".to_string()), @@ -245,6 +244,13 @@ impl DatabaseSyncEngine

{ let main_conn = connect_untracked(&self.main_tape)?; let change_id = self.meta().last_pushed_change_id_hint; let last_pull_unix_time = self.meta().last_pull_unix_time; + let revision = self.meta().synced_revision.clone().map(|x| match x { + DatabasePullRevision::Legacy { + generation, + synced_frame_no, + } => format!("generation={generation},synced_frame_no={synced_frame_no:?}"), + DatabasePullRevision::V1 { revision } => revision, + }); let last_push_unix_time = self.meta().last_push_unix_time; let revert_wal_path = &self.revert_db_wal_path; let revert_wal_file = self @@ -263,6 +269,7 @@ impl DatabaseSyncEngine

{ revert_wal_size, last_pull_unix_time, last_push_unix_time, + revision, }) } @@ -415,7 +422,6 @@ impl DatabaseSyncEngine

{ &mut self, coro: &Coro, remote_changes: DbChangesStatus, - now: turso_core::Instant, ) -> Result<()> { assert!(remote_changes.file_slot.is_some(), "file_slot must be set"); let changes_file = remote_changes.file_slot.as_ref().unwrap().value.clone(); @@ -435,7 +441,7 @@ impl DatabaseSyncEngine

{ m.revert_since_wal_watermark = revert_since_wal_watermark; m.synced_revision = Some(remote_changes.revision); m.last_pushed_change_id_hint = 0; - m.last_pull_unix_time = now.secs; + m.last_pull_unix_time = remote_changes.time.secs; }) .await?; Ok(()) @@ -655,13 +661,12 @@ impl DatabaseSyncEngine

{ } pub async fn pull_changes_from_remote(&mut self, coro: &Coro) -> Result<()> { - let now = self.io.now(); let changes = self.wait_changes_from_remote(coro).await?; if changes.file_slot.is_some() { - self.apply_changes_from_remote(coro, changes, now).await?; + self.apply_changes_from_remote(coro, changes).await?; } else { self.update_meta(coro, |m| { - m.last_pull_unix_time = now.secs; + m.last_pull_unix_time = changes.time.secs; }) .await?; } diff --git a/sync/engine/src/types.rs b/sync/engine/src/types.rs index 8837e35bf..1b78e8cb1 100644 --- a/sync/engine/src/types.rs +++ b/sync/engine/src/types.rs @@ -67,6 +67,7 @@ pub struct SyncEngineStats { pub revert_wal_size: u64, pub last_pull_unix_time: i64, pub last_push_unix_time: Option, + pub revision: Option, } #[derive(Debug, Clone, Copy, PartialEq)]