mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: remove unused code & update log (#5194)
* chore: remove unused code & update log * chore: clippy * chore: log
This commit is contained in:
parent
275d0b2ac4
commit
9aaada961f
2
.github/workflows/flutter_ci.yaml
vendored
2
.github/workflows/flutter_ci.yaml
vendored
@ -200,6 +200,8 @@ jobs:
|
||||
run: cargo make pub_get
|
||||
|
||||
- name: Run Flutter unit tests
|
||||
env:
|
||||
DISABLE_EVENT_LOG: true
|
||||
working-directory: frontend
|
||||
run: |
|
||||
if [ "$RUNNER_OS" == "macOS" ]; then
|
||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
collab = { version = "0.1.0", features = ["trace_transact"] }
|
||||
collab = { version = "0.1.0" }
|
||||
collab-plugins = { version = "0.1.0" }
|
||||
collab-entity = { version = "0.1.0" }
|
||||
serde.workspace = true
|
||||
|
@ -49,12 +49,11 @@ pub(crate) async fn get_all_workspace_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(folder), err)]
|
||||
pub(crate) async fn get_workspace_views_handler(
|
||||
data: AFPluginData<GetWorkspaceViewPB>,
|
||||
_data: AFPluginData<GetWorkspaceViewPB>,
|
||||
folder: AFPluginState<Weak<FolderManager>>,
|
||||
) -> DataResult<RepeatedViewPB, FlowyError> {
|
||||
let folder = upgrade_folder(folder)?;
|
||||
let params: GetWorkspaceViewParams = data.into_inner().try_into()?;
|
||||
let child_views = folder.get_workspace_public_views(¶ms.value).await?;
|
||||
let child_views = folder.get_workspace_public_views().await?;
|
||||
let repeated_view: RepeatedViewPB = child_views.into();
|
||||
data_result_ok(repeated_view)
|
||||
}
|
||||
@ -75,8 +74,8 @@ pub(crate) async fn read_private_views_handler(
|
||||
folder: AFPluginState<Weak<FolderManager>>,
|
||||
) -> DataResult<RepeatedViewPB, FlowyError> {
|
||||
let folder = upgrade_folder(folder)?;
|
||||
let params: GetWorkspaceViewParams = data.into_inner().try_into()?;
|
||||
let child_views = folder.get_workspace_private_views(¶ms.value).await?;
|
||||
let _params: GetWorkspaceViewParams = data.into_inner().try_into()?;
|
||||
let child_views = folder.get_workspace_private_views().await?;
|
||||
let repeated_view: RepeatedViewPB = child_views.into();
|
||||
data_result_ok(repeated_view)
|
||||
}
|
||||
@ -379,14 +378,6 @@ pub(crate) async fn get_folder_snapshots_handler(
|
||||
data_result_ok(RepeatedFolderSnapshotPB { items: snapshots })
|
||||
}
|
||||
|
||||
pub(crate) async fn reload_workspace_handler(
|
||||
folder: AFPluginState<Weak<FolderManager>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let folder = upgrade_folder(folder)?;
|
||||
folder.reload_workspace().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, folder), err)]
|
||||
pub(crate) async fn update_view_visibility_status_handler(
|
||||
data: AFPluginData<UpdateViewVisibilityStatusPayloadPB>,
|
||||
|
@ -38,7 +38,6 @@ pub fn init(folder: Weak<FolderManager>) -> AFPlugin {
|
||||
.event(FolderEvent::ReadRecentViews, read_recent_views_handler)
|
||||
.event(FolderEvent::ToggleFavorite, toggle_favorites_handler)
|
||||
.event(FolderEvent::UpdateRecentViews, update_recent_views_handler)
|
||||
.event(FolderEvent::ReloadWorkspace, reload_workspace_handler)
|
||||
.event(FolderEvent::ReadPrivateViews, read_private_views_handler)
|
||||
.event(FolderEvent::ReadCurrentWorkspaceViews, get_current_workspace_views_handler)
|
||||
.event(FolderEvent::UpdateViewVisibilityStatus, update_view_visibility_status_handler)
|
||||
@ -163,9 +162,6 @@ pub enum FolderEvent {
|
||||
#[event(input = "UpdateRecentViewPayloadPB")]
|
||||
UpdateRecentViews = 37,
|
||||
|
||||
#[event()]
|
||||
ReloadWorkspace = 38,
|
||||
|
||||
#[event(input = "GetWorkspaceViewPB", output = "RepeatedViewPB")]
|
||||
ReadPrivateViews = 39,
|
||||
|
||||
|
@ -80,28 +80,6 @@ impl FolderManager {
|
||||
Ok(manager)
|
||||
}
|
||||
|
||||
pub async fn reload_workspace(&self) -> FlowyResult<()> {
|
||||
let workspace_id = self
|
||||
.workspace_id
|
||||
.read()
|
||||
.as_ref()
|
||||
.ok_or_else(|| {
|
||||
FlowyError::internal().with_context("workspace id is empty when trying to reload workspace")
|
||||
})?
|
||||
.clone();
|
||||
|
||||
let uid = self.user.user_id()?;
|
||||
let doc_state = self
|
||||
.cloud_service
|
||||
.get_folder_doc_state(&workspace_id, uid, CollabType::Folder, &workspace_id)
|
||||
.await?;
|
||||
|
||||
self
|
||||
.initialize(uid, &workspace_id, FolderInitDataSource::Cloud(doc_state))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self), err)]
|
||||
pub async fn get_current_workspace(&self) -> FlowyResult<WorkspacePB> {
|
||||
self.with_folder(
|
||||
@ -117,7 +95,7 @@ impl FolderManager {
|
||||
},
|
||||
|folder| {
|
||||
let workspace_pb_from_workspace = |workspace: Workspace, folder: &Folder| {
|
||||
let views = get_workspace_public_view_pbs(&workspace.id, folder);
|
||||
let views = get_workspace_public_view_pbs(folder);
|
||||
let workspace: WorkspacePB = (workspace, views).into();
|
||||
Ok::<WorkspacePB, FlowyError>(workspace)
|
||||
};
|
||||
@ -139,28 +117,20 @@ impl FolderManager {
|
||||
.as_ref()
|
||||
.map(|folder| folder.get_workspace_id());
|
||||
|
||||
if let Some(workspace_id) = workspace_id {
|
||||
self.get_workspace_public_views(&workspace_id).await
|
||||
if workspace_id.is_some() {
|
||||
self.get_workspace_public_views().await
|
||||
} else {
|
||||
tracing::warn!("Can't get the workspace id from the folder. Return empty list.");
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_workspace_public_views(&self, workspace_id: &str) -> FlowyResult<Vec<ViewPB>> {
|
||||
let views = self.with_folder(Vec::new, |folder| {
|
||||
get_workspace_public_view_pbs(workspace_id, folder)
|
||||
});
|
||||
|
||||
Ok(views)
|
||||
pub async fn get_workspace_public_views(&self) -> FlowyResult<Vec<ViewPB>> {
|
||||
Ok(self.with_folder(Vec::new, get_workspace_public_view_pbs))
|
||||
}
|
||||
|
||||
pub async fn get_workspace_private_views(&self, workspace_id: &str) -> FlowyResult<Vec<ViewPB>> {
|
||||
let views = self.with_folder(Vec::new, |folder| {
|
||||
get_workspace_private_view_pbs(workspace_id, folder)
|
||||
});
|
||||
|
||||
Ok(views)
|
||||
pub async fn get_workspace_private_views(&self) -> FlowyResult<Vec<ViewPB>> {
|
||||
Ok(self.with_folder(Vec::new, get_workspace_private_view_pbs))
|
||||
}
|
||||
|
||||
pub(crate) async fn make_folder<T: Into<Option<FolderNotify>>>(
|
||||
@ -323,19 +293,6 @@ impl FolderManager {
|
||||
Ok(new_workspace)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "info", skip_all, err)]
|
||||
pub async fn open_workspace(&self, _workspace_id: &str) -> FlowyResult<Workspace> {
|
||||
self.with_folder(
|
||||
|| Err(FlowyError::internal()),
|
||||
|folder| {
|
||||
let workspace = folder.get_current_workspace().ok_or_else(|| {
|
||||
FlowyError::record_not_found().with_context("Can't open not existing workspace")
|
||||
})?;
|
||||
Ok::<Workspace, FlowyError>(workspace)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn get_workspace(&self, _workspace_id: &str) -> Option<Workspace> {
|
||||
self.with_folder(|| None, |folder| folder.get_current_workspace())
|
||||
}
|
||||
@ -1259,7 +1216,7 @@ impl FolderManager {
|
||||
}
|
||||
|
||||
/// Return the views that belong to the workspace. The views are filtered by the trash and all the private views.
|
||||
pub(crate) fn get_workspace_public_view_pbs(_workspace_id: &str, folder: &Folder) -> Vec<ViewPB> {
|
||||
pub(crate) fn get_workspace_public_view_pbs(folder: &Folder) -> Vec<ViewPB> {
|
||||
// get the trash ids
|
||||
let trash_ids = folder
|
||||
.get_all_trash_sections()
|
||||
@ -1309,7 +1266,7 @@ fn get_all_child_view_ids(folder: &Folder, view_id: &str) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// Get the current private views of the user.
|
||||
pub(crate) fn get_workspace_private_view_pbs(_workspace_id: &str, folder: &Folder) -> Vec<ViewPB> {
|
||||
pub(crate) fn get_workspace_private_view_pbs(folder: &Folder) -> Vec<ViewPB> {
|
||||
// get the trash ids
|
||||
let trash_ids = folder
|
||||
.get_all_trash_sections()
|
||||
|
@ -137,7 +137,7 @@ impl FolderManager {
|
||||
|
||||
// Index all views in the folder if needed
|
||||
if !self.folder_indexer.is_indexed() {
|
||||
let views = folder.get_all_views_recursively();
|
||||
let views = folder.views.get_all_views();
|
||||
let folder_indexer = self.folder_indexer.clone();
|
||||
|
||||
// We spawn a blocking task to index all views in the folder
|
||||
|
@ -183,8 +183,8 @@ pub(crate) fn notify_parent_view_did_change<T: AsRef<str>>(
|
||||
}
|
||||
|
||||
pub(crate) fn notify_did_update_section_views(workspace_id: &str, folder: &Folder) {
|
||||
let public_views = get_workspace_public_view_pbs(workspace_id, folder);
|
||||
let private_views = get_workspace_private_view_pbs(workspace_id, folder);
|
||||
let public_views = get_workspace_public_view_pbs(folder);
|
||||
let private_views = get_workspace_private_view_pbs(folder);
|
||||
tracing::trace!(
|
||||
"Did update section views: public len = {}, private len = {}",
|
||||
public_views.len(),
|
||||
@ -210,7 +210,7 @@ pub(crate) fn notify_did_update_section_views(workspace_id: &str, folder: &Folde
|
||||
}
|
||||
|
||||
pub(crate) fn notify_did_update_workspace(workspace_id: &str, folder: &Folder) {
|
||||
let repeated_view: RepeatedViewPB = get_workspace_public_view_pbs(workspace_id, folder).into();
|
||||
let repeated_view: RepeatedViewPB = get_workspace_public_view_pbs(folder).into();
|
||||
send_notification(workspace_id, FolderNotification::DidUpdateWorkspaceViews)
|
||||
.payload(repeated_view)
|
||||
.send();
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
use collab::core::collab::IndexContentReceiver;
|
||||
use collab_folder::{View, ViewIcon, ViewLayout};
|
||||
@ -23,5 +24,5 @@ pub trait IndexManager: Send + Sync {
|
||||
}
|
||||
|
||||
pub trait FolderIndexManager: IndexManager {
|
||||
fn index_all_views(&self, views: Vec<View>, workspace_id: String);
|
||||
fn index_all_views(&self, views: Vec<Arc<View>>, workspace_id: String);
|
||||
}
|
||||
|
@ -408,14 +408,14 @@ impl IndexManager for FolderIndexManagerImpl {
|
||||
}
|
||||
|
||||
impl FolderIndexManager for FolderIndexManagerImpl {
|
||||
fn index_all_views(&self, views: Vec<View>, workspace_id: String) {
|
||||
fn index_all_views(&self, views: Vec<Arc<View>>, workspace_id: String) {
|
||||
let indexable_data = views
|
||||
.into_iter()
|
||||
.map(|view| IndexableData {
|
||||
id: view.id,
|
||||
data: view.name,
|
||||
icon: view.icon,
|
||||
layout: view.layout,
|
||||
id: view.id.clone(),
|
||||
data: view.name.clone(),
|
||||
icon: view.icon.clone(),
|
||||
layout: view.layout.clone(),
|
||||
workspace_id: workspace_id.clone(),
|
||||
})
|
||||
.collect();
|
||||
|
@ -6,6 +6,7 @@ use serde::de::{MapAccess, Visitor};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::fmt;
|
||||
use std::fmt::Display;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@ -15,6 +16,16 @@ pub struct Session {
|
||||
pub user_workspace: UserWorkspace,
|
||||
}
|
||||
|
||||
impl Display for Session {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"user_id: {}, user_workspace: {}:{}",
|
||||
self.user_id, self.user_workspace.name, self.user_workspace.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct SessionVisitor;
|
||||
impl<'de> Visitor<'de> for SessionVisitor {
|
||||
type Value = Session;
|
||||
|
@ -492,7 +492,7 @@ pub async fn get_all_workspace_handler(
|
||||
data_result_ok(user_workspaces.into())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
#[tracing::instrument(level = "info", skip(data, manager), err)]
|
||||
pub async fn open_workspace_handler(
|
||||
data: AFPluginData<UserWorkspaceIdPB>,
|
||||
manager: AFPluginState<Weak<UserManager>>,
|
||||
|
@ -11,7 +11,7 @@ use flowy_user_pub::entities::UserWorkspace;
|
||||
use flowy_user_pub::session::Session;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Weak};
|
||||
use tracing::{debug, error, info};
|
||||
use tracing::{error, info};
|
||||
|
||||
const SQLITE_VACUUM_042: &str = "sqlite_vacuum_042_version";
|
||||
|
||||
@ -91,16 +91,17 @@ impl AuthenticateUser {
|
||||
}
|
||||
|
||||
pub fn set_session(&self, session: Option<Session>) -> Result<(), FlowyError> {
|
||||
debug!("Set current user session: {:?}", session);
|
||||
match &session {
|
||||
None => {
|
||||
self.session.write().take();
|
||||
let removed_session = self.session.write().take();
|
||||
info!("remove session: {:?}", removed_session);
|
||||
self
|
||||
.store_preferences
|
||||
.remove(self.user_config.session_cache_key.as_ref());
|
||||
Ok(())
|
||||
},
|
||||
Some(session) => {
|
||||
info!("Set current session: {:?}", session);
|
||||
self.session.write().replace(session.clone());
|
||||
self
|
||||
.store_preferences
|
||||
|
@ -710,7 +710,10 @@ impl UserManager {
|
||||
}
|
||||
|
||||
save_user_workspaces(uid, self.db_connection(uid)?, response.user_workspaces())?;
|
||||
event!(tracing::Level::INFO, "Save new user profile to disk");
|
||||
info!(
|
||||
"Save new user profile to disk, authenticator: {:?}",
|
||||
authenticator
|
||||
);
|
||||
|
||||
self.authenticate_user.set_session(Some(session.clone()))?;
|
||||
self
|
||||
|
@ -135,6 +135,7 @@ impl UserManager {
|
||||
|
||||
#[instrument(skip(self), err)]
|
||||
pub async fn open_workspace(&self, workspace_id: &str) -> FlowyResult<()> {
|
||||
info!("open workspace: {}", workspace_id);
|
||||
let uid = self.user_id()?;
|
||||
let user_workspace = self
|
||||
.cloud_services
|
||||
|
@ -1,3 +1,4 @@
|
||||
use chrono::Local;
|
||||
use std::{fmt, io::Write};
|
||||
|
||||
use serde::ser::{SerializeMap, Serializer};
|
||||
@ -45,7 +46,7 @@ where
|
||||
) -> Result<(), std::io::Error> {
|
||||
map_serializer.serialize_entry(MESSAGE, &message)?;
|
||||
// map_serializer.serialize_entry(LEVEL, &format!("{}", level))?;
|
||||
// map_serializer.serialize_entry(TIME, &chrono::Utc::now().timestamp())?;
|
||||
map_serializer.serialize_entry(TIME, &Local::now().format("%Y-%m-%d %H:%M:%S").to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -114,12 +114,9 @@ impl<'a> MakeWriter<'a> for DebugStdoutWriter {
|
||||
type Writer = Box<dyn Write>;
|
||||
|
||||
fn make_writer(&'a self) -> Self::Writer {
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
if std::env::var("DISABLE_EVENT_LOG").unwrap_or("false".to_string()) == "true" {
|
||||
Box::new(io::sink())
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
} else {
|
||||
Box::new(io::stdout())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user