mod.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. mod folder_rev_impl;
  2. mod grid_block_meta_rev_impl;
  3. mod grid_rev_impl;
  4. mod text_rev_impl;
  5. pub use folder_rev_impl::*;
  6. pub use grid_block_meta_rev_impl::*;
  7. pub use grid_rev_impl::*;
  8. pub use text_rev_impl::*;
  9. use flowy_error::FlowyResult;
  10. use flowy_sync::entities::revision::{RevId, Revision, RevisionRange};
  11. use std::fmt::Debug;
  12. pub trait RevisionDiskCache: Sync + Send {
  13. type Error: Debug;
  14. fn create_revision_records(&self, revision_records: Vec<RevisionRecord>) -> Result<(), Self::Error>;
  15. // Read all the records if the rev_ids is None
  16. fn read_revision_records(
  17. &self,
  18. object_id: &str,
  19. rev_ids: Option<Vec<i64>>,
  20. ) -> Result<Vec<RevisionRecord>, Self::Error>;
  21. // Read the revision which rev_id >= range.start && rev_id <= range.end
  22. fn read_revision_records_with_range(
  23. &self,
  24. object_id: &str,
  25. range: &RevisionRange,
  26. ) -> Result<Vec<RevisionRecord>, Self::Error>;
  27. fn update_revision_record(&self, changesets: Vec<RevisionChangeset>) -> FlowyResult<()>;
  28. // Delete all the records if the rev_ids is None
  29. fn delete_revision_records(&self, object_id: &str, rev_ids: Option<Vec<i64>>) -> Result<(), Self::Error>;
  30. // Delete and insert will be executed in the same transaction.
  31. // It deletes all the records if the deleted_rev_ids is None and then insert the new records
  32. fn delete_and_insert_records(
  33. &self,
  34. object_id: &str,
  35. deleted_rev_ids: Option<Vec<i64>>,
  36. inserted_records: Vec<RevisionRecord>,
  37. ) -> Result<(), Self::Error>;
  38. }
  39. #[derive(Clone, Debug)]
  40. pub struct RevisionRecord {
  41. pub revision: Revision,
  42. pub state: RevisionState,
  43. pub write_to_disk: bool,
  44. }
  45. impl RevisionRecord {
  46. pub fn ack(&mut self) {
  47. self.state = RevisionState::Ack;
  48. }
  49. }
  50. pub struct RevisionChangeset {
  51. pub(crate) object_id: String,
  52. pub(crate) rev_id: RevId,
  53. pub(crate) state: RevisionState,
  54. }
  55. #[derive(Debug, Clone, Eq, PartialEq)]
  56. pub enum RevisionState {
  57. Sync = 0,
  58. Ack = 1,
  59. }
  60. impl RevisionState {
  61. pub fn is_need_sync(&self) -> bool {
  62. match self {
  63. RevisionState::Sync => true,
  64. RevisionState::Ack => false,
  65. }
  66. }
  67. }
  68. impl AsRef<RevisionState> for RevisionState {
  69. fn as_ref(&self) -> &RevisionState {
  70. self
  71. }
  72. }