Skip to content

Commit b62a586

Browse files
committed
libsql: move push_one_frame to sync.rs
1 parent 72c6bd1 commit b62a586

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

libsql/src/local/database.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,15 @@ impl Database {
406406

407407
let mut frame_no = start_frame_no;
408408
while frame_no <= end_frame_no {
409+
let frame = conn.wal_get_frame(frame_no, page_size)?;
410+
409411
// The server returns its maximum frame number. To avoid resending
410412
// frames the server already knows about, we need to update the
411413
// frame number to the one returned by the server.
412-
let max_frame_no = self
413-
.push_one_frame(&conn, &sync_ctx, generation, frame_no, page_size)
414+
let max_frame_no = sync_ctx
415+
.push_one_frame(frame.to_vec(), generation, frame_no)
414416
.await?;
417+
415418
if max_frame_no > frame_no {
416419
frame_no = max_frame_no;
417420
}
@@ -425,35 +428,6 @@ impl Database {
425428
})
426429
}
427430

428-
#[cfg(feature = "sync")]
429-
async fn push_one_frame(
430-
&self,
431-
conn: &Connection,
432-
sync_ctx: &SyncContext,
433-
generation: u32,
434-
frame_no: u32,
435-
page_size: u32,
436-
) -> Result<u32> {
437-
let frame = conn.wal_get_frame(frame_no, page_size)?;
438-
439-
let uri = format!(
440-
"{}/sync/{}/{}/{}",
441-
sync_ctx.sync_url,
442-
generation,
443-
frame_no,
444-
frame_no + 1
445-
);
446-
let max_frame_no = sync_ctx
447-
.push_with_retry(
448-
uri,
449-
&sync_ctx.auth_token,
450-
frame.to_vec(),
451-
sync_ctx.max_retries,
452-
)
453-
.await?;
454-
Ok(max_frame_no)
455-
}
456-
457431
pub(crate) fn path(&self) -> &str {
458432
&self.db_path
459433
}

libsql/src/sync.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,27 @@ impl SyncContext {
1818
}
1919
}
2020

21-
pub(crate) async fn push_with_retry(
21+
pub(crate) async fn push_one_frame(
22+
&self,
23+
frame: Vec<u8>,
24+
generation: u32,
25+
frame_no: u32,
26+
) -> Result<u32> {
27+
let uri = format!(
28+
"{}/sync/{}/{}/{}",
29+
self.sync_url,
30+
generation,
31+
frame_no,
32+
frame_no + 1
33+
);
34+
let max_frame_no = self
35+
.push_with_retry(uri, &self.auth_token, frame.to_vec(), self.max_retries)
36+
.await?;
37+
38+
Ok(max_frame_no)
39+
}
40+
41+
async fn push_with_retry(
2242
&self,
2343
uri: String,
2444
auth_token: &Option<String>,

0 commit comments

Comments
 (0)