mirror of
https://github.com/ankitects/anki.git
synced 2025-12-11 05:46:55 -05:00
handle non-chunked graves from AnkiDroid
This commit is contained in:
parent
ed7e709285
commit
a77aa6b65a
5 changed files with 36 additions and 8 deletions
|
|
@ -99,7 +99,11 @@ impl Backend {
|
|||
|
||||
self.with_sync_server(|server| {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(server.start(input.client_usn, input.local_is_newer))
|
||||
rt.block_on(server.start(
|
||||
input.client_usn,
|
||||
input.local_is_newer,
|
||||
input.deprecated_client_graves,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@ pub struct StartIn {
|
|||
pub client_usn: Usn,
|
||||
#[serde(rename = "lnewer")]
|
||||
pub local_is_newer: bool,
|
||||
/// Unfortunately AnkiDroid is still using this
|
||||
#[serde(rename = "graves", default)]
|
||||
pub deprecated_client_graves: Option<Graves>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -71,10 +71,16 @@ impl SyncServer for HTTPSyncClient {
|
|||
self.json_request(input).await
|
||||
}
|
||||
|
||||
async fn start(&mut self, client_usn: Usn, local_is_newer: bool) -> Result<Graves> {
|
||||
async fn start(
|
||||
&mut self,
|
||||
client_usn: Usn,
|
||||
local_is_newer: bool,
|
||||
deprecated_client_graves: Option<Graves>,
|
||||
) -> Result<Graves> {
|
||||
let input = SyncRequest::Start(StartIn {
|
||||
client_usn,
|
||||
local_is_newer,
|
||||
deprecated_client_graves,
|
||||
});
|
||||
self.json_request(input).await
|
||||
}
|
||||
|
|
@ -362,13 +368,13 @@ mod test {
|
|||
})
|
||||
));
|
||||
|
||||
let _graves = syncer.start(Usn(1), true).await?;
|
||||
let _graves = syncer.start(Usn(1), true, None).await?;
|
||||
|
||||
// aborting should now work
|
||||
syncer.abort().await?;
|
||||
|
||||
// start again, and continue
|
||||
let _graves = syncer.start(Usn(1), true).await?;
|
||||
let _graves = syncer.start(Usn(1), true, None).await?;
|
||||
|
||||
syncer.apply_graves(Graves::default()).await?;
|
||||
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ where
|
|||
async fn start_and_process_deletions(&mut self, state: &SyncState) -> Result<()> {
|
||||
let remote: Graves = self
|
||||
.remote
|
||||
.start(state.usn_at_last_sync, state.local_is_newer)
|
||||
.start(state.usn_at_last_sync, state.local_is_newer, None)
|
||||
.await?;
|
||||
|
||||
debug!(self.col.log, "removed on remote";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,12 @@ use super::ChunkableIDs;
|
|||
#[async_trait(?Send)]
|
||||
pub trait SyncServer {
|
||||
async fn meta(&self) -> Result<SyncMeta>;
|
||||
async fn start(&mut self, client_usn: Usn, local_is_newer: bool) -> Result<Graves>;
|
||||
async fn start(
|
||||
&mut self,
|
||||
client_usn: Usn,
|
||||
local_is_newer: bool,
|
||||
deprecated_client_graves: Option<Graves>,
|
||||
) -> Result<Graves>;
|
||||
async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()>;
|
||||
async fn apply_changes(&mut self, client_changes: UnchunkedChanges)
|
||||
-> Result<UnchunkedChanges>;
|
||||
|
|
@ -84,13 +89,23 @@ impl SyncServer for LocalServer {
|
|||
})
|
||||
}
|
||||
|
||||
async fn start(&mut self, client_usn: Usn, client_is_newer: bool) -> Result<Graves> {
|
||||
async fn start(
|
||||
&mut self,
|
||||
client_usn: Usn,
|
||||
client_is_newer: bool,
|
||||
deprecated_client_graves: Option<Graves>,
|
||||
) -> Result<Graves> {
|
||||
self.server_usn = self.col.usn()?;
|
||||
self.client_usn = client_usn;
|
||||
self.client_is_newer = client_is_newer;
|
||||
|
||||
self.col.storage.begin_rust_trx()?;
|
||||
self.col.storage.pending_graves(client_usn)
|
||||
let server_graves = self.col.storage.pending_graves(client_usn)?;
|
||||
// Handle AnkiDroid using old protocol
|
||||
if let Some(graves) = deprecated_client_graves {
|
||||
self.col.apply_graves(graves, self.server_usn)?;
|
||||
}
|
||||
Ok(server_graves)
|
||||
}
|
||||
|
||||
async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue