2022-08-14 23:11:30 +08:00
|
|
|
mod document_impl;
|
|
|
|
mod grid_block_impl;
|
|
|
|
mod grid_impl;
|
2022-08-15 20:07:01 +08:00
|
|
|
mod grid_view_impl;
|
2022-03-10 17:14:10 +08:00
|
|
|
|
2022-08-14 23:11:30 +08:00
|
|
|
pub use document_impl::*;
|
|
|
|
pub use grid_block_impl::*;
|
|
|
|
pub use grid_impl::*;
|
2022-08-15 20:07:01 +08:00
|
|
|
pub use grid_view_impl::*;
|
2022-03-10 17:14:10 +08:00
|
|
|
|
2022-01-04 15:05:52 +08:00
|
|
|
use flowy_error::FlowyResult;
|
2022-03-19 16:52:28 +08:00
|
|
|
use flowy_sync::entities::revision::{RevId, Revision, RevisionRange};
|
2022-01-04 15:05:52 +08:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
2022-01-14 15:23:21 +08:00
|
|
|
pub trait RevisionDiskCache: Sync + Send {
|
2022-01-04 15:05:52 +08:00
|
|
|
type Error: Debug;
|
2022-03-11 21:36:00 +08:00
|
|
|
fn create_revision_records(&self, revision_records: Vec<RevisionRecord>) -> Result<(), Self::Error>;
|
2022-01-04 15:05:52 +08:00
|
|
|
|
|
|
|
// Read all the records if the rev_ids is None
|
|
|
|
fn read_revision_records(
|
|
|
|
&self,
|
2022-01-14 15:23:21 +08:00
|
|
|
object_id: &str,
|
2022-01-04 15:05:52 +08:00
|
|
|
rev_ids: Option<Vec<i64>>,
|
|
|
|
) -> Result<Vec<RevisionRecord>, Self::Error>;
|
|
|
|
|
2022-01-25 20:37:48 +08:00
|
|
|
// Read the revision which rev_id >= range.start && rev_id <= range.end
|
2022-01-04 15:05:52 +08:00
|
|
|
fn read_revision_records_with_range(
|
|
|
|
&self,
|
2022-01-14 15:23:21 +08:00
|
|
|
object_id: &str,
|
2022-01-04 15:05:52 +08:00
|
|
|
range: &RevisionRange,
|
|
|
|
) -> Result<Vec<RevisionRecord>, Self::Error>;
|
|
|
|
|
|
|
|
fn update_revision_record(&self, changesets: Vec<RevisionChangeset>) -> FlowyResult<()>;
|
|
|
|
|
|
|
|
// Delete all the records if the rev_ids is None
|
2022-01-27 14:06:59 +08:00
|
|
|
fn delete_revision_records(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> Result<(), Self::Error>;
|
2022-01-04 15:05:52 +08:00
|
|
|
|
2022-01-26 23:29:18 +08:00
|
|
|
// Delete and insert will be executed in the same transaction.
|
|
|
|
// It deletes all the records if the deleted_rev_ids is None and then insert the new records
|
|
|
|
fn delete_and_insert_records(
|
|
|
|
&self,
|
|
|
|
object_id: &str,
|
|
|
|
deleted_rev_ids: Option<Vec<i64>>,
|
|
|
|
inserted_records: Vec<RevisionRecord>,
|
|
|
|
) -> Result<(), Self::Error>;
|
2022-01-04 15:05:52 +08:00
|
|
|
}
|
2022-03-10 22:27:19 +08:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct RevisionRecord {
|
|
|
|
pub revision: Revision,
|
|
|
|
pub state: RevisionState,
|
|
|
|
pub write_to_disk: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RevisionRecord {
|
2022-07-20 18:27:12 +08:00
|
|
|
pub fn new(revision: Revision) -> Self {
|
|
|
|
Self {
|
|
|
|
revision,
|
|
|
|
state: RevisionState::Sync,
|
|
|
|
write_to_disk: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-10 22:27:19 +08:00
|
|
|
pub fn ack(&mut self) {
|
|
|
|
self.state = RevisionState::Ack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct RevisionChangeset {
|
|
|
|
pub(crate) object_id: String,
|
|
|
|
pub(crate) rev_id: RevId,
|
|
|
|
pub(crate) state: RevisionState,
|
|
|
|
}
|
|
|
|
|
2022-07-20 18:27:12 +08:00
|
|
|
/// Sync: revision is not synced to the server
|
|
|
|
/// Ack: revision is synced to the server
|
2022-03-10 22:27:19 +08:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub enum RevisionState {
|
|
|
|
Sync = 0,
|
|
|
|
Ack = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RevisionState {
|
|
|
|
pub fn is_need_sync(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
RevisionState::Sync => true,
|
|
|
|
RevisionState::Ack => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsRef<RevisionState> for RevisionState {
|
|
|
|
fn as_ref(&self) -> &RevisionState {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|