mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: compose folder error
This commit is contained in:
@ -197,9 +197,9 @@ impl DefaultFolderBuilder {
|
||||
for app in workspace.apps.iter() {
|
||||
for (index, view) in app.belongings.iter().enumerate() {
|
||||
let view_data = if index == 0 {
|
||||
initial_read_me().to_json()
|
||||
initial_read_me().to_delta_json()
|
||||
} else {
|
||||
initial_delta().to_json()
|
||||
initial_delta().to_delta_json()
|
||||
};
|
||||
view_controller.set_latest_view(view);
|
||||
let delta_data = Bytes::from(view_data);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::controller::FolderId;
|
||||
use crate::{
|
||||
event_map::WorkspaceDatabase,
|
||||
services::persistence::{AppTableSql, TrashTableSql, ViewTableSql, WorkspaceTableSql},
|
||||
@ -10,9 +11,11 @@ use flowy_folder_data_model::entities::{
|
||||
view::{RepeatedView, View},
|
||||
workspace::Workspace,
|
||||
};
|
||||
use flowy_sync::{RevisionLoader, RevisionPersistence};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) const V1_MIGRATION: &str = "FOLDER_V1_MIGRATION";
|
||||
const V1_MIGRATION: &str = "FOLDER_V1_MIGRATION";
|
||||
const V2_MIGRATION: &str = "FOLDER_V2_MIGRATION";
|
||||
|
||||
pub(crate) struct FolderMigration {
|
||||
user_id: String,
|
||||
@ -32,7 +35,7 @@ impl FolderMigration {
|
||||
if KV::get_bool(&key) {
|
||||
return Ok(None);
|
||||
}
|
||||
tracing::trace!("Run folder version 1 migrations");
|
||||
|
||||
let pool = self.database.db_pool()?;
|
||||
let conn = &*pool.get()?;
|
||||
let workspaces = conn.immediate_transaction::<_, FlowyError, _>(|| {
|
||||
@ -62,6 +65,7 @@ impl FolderMigration {
|
||||
})?;
|
||||
|
||||
if workspaces.is_empty() {
|
||||
tracing::trace!("Run folder v1 migration, but workspace is empty");
|
||||
KV::set_bool(&key, true);
|
||||
return Ok(None);
|
||||
}
|
||||
@ -73,6 +77,35 @@ impl FolderMigration {
|
||||
|
||||
let folder = FolderPad::new(workspaces, trash)?;
|
||||
KV::set_bool(&key, true);
|
||||
tracing::trace!("Run folder v1 migration");
|
||||
Ok(Some(folder))
|
||||
}
|
||||
|
||||
pub async fn run_v2_migration(&self, user_id: &str, folder_id: &FolderId) -> FlowyResult<Option<FolderPad>> {
|
||||
let key = md5(format!("{}{}", self.user_id, V2_MIGRATION));
|
||||
if KV::get_bool(&key) {
|
||||
return Ok(None);
|
||||
}
|
||||
let pool = self.database.db_pool()?;
|
||||
let rev_persistence = Arc::new(RevisionPersistence::new(user_id, folder_id.as_ref(), pool.clone()));
|
||||
let (revisions, _) = RevisionLoader {
|
||||
object_id: folder_id.as_ref().to_owned(),
|
||||
user_id: self.user_id.clone(),
|
||||
cloud: None,
|
||||
rev_persistence,
|
||||
}
|
||||
.load()
|
||||
.await?;
|
||||
|
||||
if revisions.is_empty() {
|
||||
tracing::trace!("Run folder v2 migration, but revision is empty");
|
||||
KV::set_bool(&key, true);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let pad = FolderPad::from_revisions(revisions)?;
|
||||
KV::set_bool(&key, true);
|
||||
tracing::trace!("Run folder v2 migration");
|
||||
Ok(Some(pad))
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ mod migration;
|
||||
pub mod version_1;
|
||||
mod version_2;
|
||||
|
||||
use flowy_collaboration::client_folder::initial_folder_delta;
|
||||
use flowy_collaboration::{
|
||||
client_folder::FolderPad,
|
||||
entities::revision::{Revision, RevisionState},
|
||||
@ -105,7 +106,10 @@ impl FolderPersistence {
|
||||
pub async fn initialize(&self, user_id: &str, folder_id: &FolderId) -> FlowyResult<()> {
|
||||
let migrations = FolderMigration::new(user_id, self.database.clone());
|
||||
if let Some(migrated_folder) = migrations.run_v1_migration()? {
|
||||
tracing::trace!("Save migration folder");
|
||||
self.save_folder(user_id, folder_id, migrated_folder).await?;
|
||||
}
|
||||
|
||||
if let Some(migrated_folder) = migrations.run_v2_migration(user_id, folder_id).await? {
|
||||
self.save_folder(user_id, folder_id, migrated_folder).await?;
|
||||
}
|
||||
|
||||
@ -114,7 +118,7 @@ impl FolderPersistence {
|
||||
|
||||
pub async fn save_folder(&self, user_id: &str, folder_id: &FolderId, folder: FolderPad) -> FlowyResult<()> {
|
||||
let pool = self.database.db_pool()?;
|
||||
let delta_data = folder.delta().to_bytes();
|
||||
let delta_data = initial_folder_delta(&folder)?.to_bytes();
|
||||
let md5 = folder.md5();
|
||||
let revision = Revision::new(folder_id.as_ref(), 0, 0, delta_data, user_id, md5);
|
||||
let record = RevisionRecord {
|
||||
@ -123,8 +127,7 @@ impl FolderPersistence {
|
||||
write_to_disk: true,
|
||||
};
|
||||
|
||||
let conn = pool.get()?;
|
||||
let disk_cache = mk_revision_disk_cache(user_id, pool);
|
||||
disk_cache.create_revision_records(vec![record], &conn)
|
||||
disk_cache.delete_and_insert_records(folder_id.as_ref(), None, vec![record])
|
||||
}
|
||||
}
|
||||
|
@ -109,13 +109,13 @@ pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) {
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, view_type: ViewDataType) -> View {
|
||||
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> View {
|
||||
let request = CreateViewPayload {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
thumbnail: None,
|
||||
data_type: view_type,
|
||||
data_type,
|
||||
ext_data: "".to_string(),
|
||||
plugin_type: 0,
|
||||
};
|
||||
|
Reference in New Issue
Block a user