mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Feat/restore revision (#1549)
* chore: write snapshot * chore: add tests * chore: sync close * chore: restore from snapshot * chore: delete invalid revisions after restored from snapshot * chore: create default view if it fail to deserialize view's revisions when there is no snapshot * chore: auto generate snapshot Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
@ -12,4 +12,4 @@ pin-project = "1.0"
|
||||
futures-core = { version = "0.3" }
|
||||
tokio = { version = "1.0", features = ["time", "rt"] }
|
||||
rand = "0.8.5"
|
||||
|
||||
async-trait = "0.1.59"
|
@ -8,7 +8,7 @@ use std::{
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
pub fn to_future<T, O>(f: T) -> Fut<O>
|
||||
pub fn to_fut<T, O>(f: T) -> Fut<O>
|
||||
where
|
||||
T: Future<Output = O> + Send + Sync + 'static,
|
||||
{
|
||||
|
@ -2,3 +2,5 @@ pub mod future;
|
||||
pub mod ref_map;
|
||||
pub mod retry;
|
||||
pub mod util;
|
||||
|
||||
pub use async_trait;
|
||||
|
@ -1,8 +1,10 @@
|
||||
use async_trait::async_trait;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[async_trait]
|
||||
pub trait RefCountValue {
|
||||
fn did_remove(&self) {}
|
||||
async fn did_remove(&self) {}
|
||||
}
|
||||
|
||||
struct RefCountHandler<T> {
|
||||
@ -30,7 +32,7 @@ impl<T> std::default::Default for RefCountHashMap<T> {
|
||||
|
||||
impl<T> RefCountHashMap<T>
|
||||
where
|
||||
T: Clone + Send + Sync + RefCountValue,
|
||||
T: Clone + Send + Sync + RefCountValue + 'static,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
@ -53,7 +55,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, key: &str) {
|
||||
pub async fn remove(&mut self, key: &str) {
|
||||
let mut should_remove = false;
|
||||
if let Some(value) = self.0.get_mut(key) {
|
||||
if value.ref_count > 0 {
|
||||
@ -64,17 +66,20 @@ where
|
||||
|
||||
if should_remove {
|
||||
if let Some(handler) = self.0.remove(key) {
|
||||
handler.inner.did_remove();
|
||||
tokio::spawn(async move {
|
||||
handler.inner.did_remove().await;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T> RefCountValue for Arc<T>
|
||||
where
|
||||
T: RefCountValue,
|
||||
T: RefCountValue + Sync + Send,
|
||||
{
|
||||
fn did_remove(&self) {
|
||||
(**self).did_remove()
|
||||
async fn did_remove(&self) {
|
||||
(**self).did_remove().await
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user