sync looks like it's working

This commit is contained in:
Ellie Huxtable
2023-12-03 12:48:40 +00:00
parent eff7de4720
commit 5ae35b40db
3 changed files with 18 additions and 27 deletions

View File

@ -242,20 +242,11 @@ impl<'a> Client<'a> {
);
let url = format!(
"{}/record/next?host={}&tag={}&count={}",
self.sync_addr, host.0, tag, count
"{}/record/next?host={}&tag={}&count={}&start={}",
self.sync_addr, host.0, tag, count, start
);
let mut url = Url::parse(url.as_str())?;
if let Some(start) = start {
url.set_query(Some(
format!(
"host={}&tag={}&count={}&start={}",
host.0, tag, count, start.0
)
.as_str(),
));
}
let url = Url::parse(url.as_str())?;
let resp = self.client.get(url).send().await?;

View File

@ -154,7 +154,8 @@ async fn sync_upload(
local: RecordIdx,
remote: Option<RecordIdx>,
) -> Result<i64, SyncError> {
let expected = local - remote.unwrap_or(0);
let remote = remote.unwrap_or(0);
let expected = local - remote;
let upload_page_size = 100;
let mut progress = 0;
@ -168,12 +169,7 @@ async fn sync_upload(
// preload with the first entry if remote does not know of this store
while progress < expected {
let page = store
.next(
host,
tag.as_str(),
remote.unwrap_or(0) + progress,
upload_page_size,
)
.next(host, tag.as_str(), remote + progress, upload_page_size)
.await
.map_err(|_| SyncError::LocalStoreError)?;
@ -203,7 +199,7 @@ async fn sync_download(
remote: RecordIdx,
) -> Result<i64, SyncError> {
let local = local.unwrap_or(0);
let expected = remote - local.unwrap_or(0);
let expected = remote - local;
let download_page_size = 100;
let mut progress = 0;
@ -216,25 +212,27 @@ async fn sync_download(
// preload with the first entry if remote does not know of this store
while progress < expected {
let page = client.next_records(host, tag, Some(local + progress), download_page_size);
let _ = client
.post_records(&page)
let page = client
.next_records(host, tag.clone(), local + progress, download_page_size)
.await
.map_err(|_| SyncError::RemoteRequestError)?;
store
.push_batch(page.iter())
.await
.map_err(|_| SyncError::LocalStoreError)?;
println!(
"uploaded {} to remote, progress {}/{}",
"downloaded {} records from remote, progress {}/{}",
page.len(),
progress,
expected
);
progress += page.len() as u64;
}
Ok(progress as i64)
Ok(0)
}
pub async fn sync_remote(

View File

@ -0,0 +1,2 @@
-- Add migration script here
create unique index record_uniq ON store(user_id, host, tag, idx);