Skip to content

Commit

Permalink
chore: update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Oct 15, 2024
1 parent 46a3006 commit db26fd8
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions frontend/rust-lib/flowy-folder/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ use futures::future;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::sync::{Arc, Weak};
use tracing::{error, info, instrument};
use tokio::sync::RwLockWriteGuard;
use tracing::{error, info, instrument, warn};

pub trait FolderUser: Send + Sync {
fn user_id(&self) -> Result<i64, FlowyError>;
Expand Down Expand Up @@ -380,6 +381,7 @@ impl FolderManager {
/// it will be used to set the `parent_view_id` for all child views. If not, the latest
/// view (by `last_edited_time`) from the workspace will be used as the parent view.
///
#[instrument(level = "info", skip_all, err)]
pub async fn insert_views_with_parent(
&self,
mut views: Vec<ParentChildViews>,
Expand All @@ -393,7 +395,7 @@ impl FolderManager {

// Obtain a write lock on the folder.
let mut folder = lock.write().await;

let parent_view_id = parent_view_id.as_deref().filter(|id| !id.is_empty());
// Set the parent view ID for the child views.
if let Some(parent_view_id) = parent_view_id {
// If a valid parent_view_id is provided, set it for each child view.
Expand All @@ -403,34 +405,18 @@ impl FolderManager {
parent_view_id
);
views.iter_mut().for_each(|child_view| {
child_view.view.parent_view_id = parent_view_id.clone();
child_view.view.parent_view_id = parent_view_id.to_string();
});
} else {
error!(
"[AppFlowyData]: The provided parent_view_id: {} is not found in the folder",
parent_view_id
);
Self::insert_into_latest_view(&mut views, &mut folder)?;
}
} else {
// If no parent_view_id is provided, find the latest view in the workspace.
let workspace_id = folder
.get_workspace_id()
.ok_or_else(|| FlowyError::internal().with_context("Cannot find the workspace ID"))?;

// Get the latest view based on the last_edited_time in the workspace.
match folder
.get_views_belong_to(&workspace_id)
.iter()
.max_by_key(|view| view.last_edited_time)
{
None => info!("[AppFlowyData]: No views found in the workspace"),
Some(latest_view) => {
info!(
"[AppFlowyData]: Attach parent-child views with the latest view: {}:{}, is_space: {:?}",
latest_view.id,
latest_view.name,
latest_view.space_info(),
);
views.iter_mut().for_each(|child_view| {
child_view.view.parent_view_id = latest_view.id.clone();
});
},
}
Self::insert_into_latest_view(&mut views, &mut folder)?;
}

// Insert the views into the folder.
Expand All @@ -439,6 +425,37 @@ impl FolderManager {
Ok(())
}

#[instrument(level = "info", skip_all, err)]
fn insert_into_latest_view(
views: &mut Vec<ParentChildViews>,
folder: &mut RwLockWriteGuard<Folder>,
) -> Result<(), FlowyError> {
let workspace_id = folder
.get_workspace_id()
.ok_or_else(|| FlowyError::internal().with_context("Cannot find the workspace ID"))?;

// Get the latest view based on the last_edited_time in the workspace.
match folder
.get_views_belong_to(&workspace_id)
.iter()
.max_by_key(|view| view.last_edited_time)
{
None => info!("[AppFlowyData]: No views found in the workspace"),
Some(latest_view) => {
info!(
"[AppFlowyData]: Attach parent-child views with the latest view: {}:{}, is_space: {:?}",
latest_view.id,
latest_view.name,
latest_view.space_info(),
);
views.iter_mut().for_each(|child_view| {
child_view.view.parent_view_id = latest_view.id.clone();
});
},
}
Ok(())
}

pub async fn get_workspace_pb(&self) -> FlowyResult<WorkspacePB> {
let workspace_id = self.user.workspace_id()?;
let lock = self
Expand Down

0 comments on commit db26fd8

Please sign in to comment.