Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: remove unused code

Nathanc89f33e2f89f
diff --git a/frontend/appflowy_flutter/lib/user/application/workspace_error_bloc.dart b/frontend/appflowy_flutter/lib/user/application/workspace_error_bloc.dart
index ce51fdd10b..7ff50dbd02 100644
--- a/frontend/appflowy_flutter/lib/user/application/workspace_error_bloc.dart
+++ b/frontend/appflowy_flutter/lib/user/application/workspace_error_bloc.dart
@@ -1,9 +1,7 @@
import 'package:appflowy/plugins/database/application/defines.dart';
-import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -22,20 +20,10 @@ class WorkspaceErrorBloc
void _dispatch() {
on<WorkspaceErrorEvent>(
(event, emit) async {
- await event.when(
+ event.when(
init: () {
// _loadSnapshots();
},
- resetWorkspace: () async {
- emit(state.copyWith(loadingState: const LoadingState.loading()));
- final payload = ResetWorkspacePB.create()
- ..workspaceId = userFolder.workspaceId
- ..uid = userFolder.uid;
- final result = await UserEventResetWorkspace(payload).send();
- if (!isClosed) {
- add(WorkspaceErrorEvent.didResetWorkspace(result));
- }
- },
didResetWorkspace: (result) {
result.fold(
(_) {
@@ -68,7 +56,6 @@ class WorkspaceErrorBloc
class WorkspaceErrorEvent with _$WorkspaceErrorEvent {
const factory WorkspaceErrorEvent.init() = _Init;
const factory WorkspaceErrorEvent.logout() = _DidLogout;
- const factory WorkspaceErrorEvent.resetWorkspace() = _ResetWorkspace;
const factory WorkspaceErrorEvent.didResetWorkspace(
FlowyResult<void, FlowyError> result,
) = _DidResetWorkspace;
diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_error_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_error_screen.dart
index d79127e04c..bd32696514 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_error_screen.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_error_screen.dart
@@ -86,7 +86,6 @@ class WorkspaceErrorScreen extends StatelessWidget {
const VSpace(50),
const LogoutButton(),
const VSpace(20),
- const ResetWorkspaceButton(),
]);
return Center(
@@ -157,43 +156,3 @@ class LogoutButton extends StatelessWidget {
);
}
}
-
-class ResetWorkspaceButton extends StatelessWidget {
- const ResetWorkspaceButton({super.key});
-
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- width: 200,
- height: 40,
- child: BlocBuilder<WorkspaceErrorBloc, WorkspaceErrorState>(
- builder: (context, state) {
- final isLoading = state.loadingState?.isLoading() ?? false;
- final icon = isLoading
- ? const Center(
- child: CircularProgressIndicator.adaptive(),
- )
- : null;
-
- return FlowyButton(
- text: FlowyText.medium(
- LocaleKeys.workspace_reset.tr(),
- textAlign: TextAlign.center,
- ),
- onTap: () {
- NavigatorAlertDialog(
- title: LocaleKeys.workspace_resetWorkspacePrompt.tr(),
- confirm: () {
- context.read<WorkspaceErrorBloc>().add(
- const WorkspaceErrorEvent.resetWorkspace(),
- );
- },
- ).show(context);
- },
- rightIcon: icon,
- );
- },
- ),
- );
- }
-}
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index 8e46148ea9..ac47524944 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -2957,7 +2957,6 @@ dependencies = [
"arc-swap",
"assert-json-diff",
"bytes",
- "chrono",
"client-api",
"collab",
"collab-database",
@@ -2966,7 +2965,6 @@ dependencies = [
"collab-folder",
"collab-plugins",
"collab-user",
- "dashmap 6.0.1",
"dotenv",
"flowy-ai-pub",
"flowy-database-pub",
@@ -2975,33 +2973,25 @@ dependencies = [
"flowy-folder-pub",
"flowy-search-pub",
"flowy-server-pub",
+ "flowy-sqlite",
"flowy-storage",
"flowy-storage-pub",
"flowy-user-pub",
"futures",
"futures-util",
- "hex",
- "hyper 0.14.27",
"lazy_static",
- "lib-dispatch",
"lib-infra",
- "mime_guess",
- "postgrest",
"rand 0.8.5",
- "reqwest 0.11.27",
"semver",
"serde",
"serde_json",
"thiserror 1.0.64",
"tokio",
- "tokio-retry",
"tokio-stream",
"tokio-util",
"tracing",
"tracing-subscriber",
- "url",
"uuid",
- "yrs",
]
[[package]]
@@ -3138,6 +3128,7 @@ name = "flowy-user-pub"
version = "0.1.0"
dependencies = [
"anyhow",
+ "arc-swap",
"base64 0.21.5",
"chrono",
"client-api",
@@ -5382,15 +5373,6 @@ dependencies = [
"postgres-protocol",
]
-[[package]]
-name = "postgrest"
-version = "1.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a966c650b47a064e7082170b4be74fca08c088d893244fc4b70123e3c1f3ee7"
-dependencies = [
- "reqwest 0.11.27",
-]
-
[[package]]
name = "powerfmt"
version = "0.2.0"
@@ -6130,7 +6112,6 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
- "webpki-roots 0.25.2",
"winreg 0.50.0",
]
@@ -8443,12 +8424,6 @@ dependencies = [
"webpki",
]
-[[package]]
-name = "webpki-roots"
-version = "0.25.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc"
-
[[package]]
name = "webpki-roots"
version = "0.26.7"
diff --git a/frontend/rust-lib/flowy-ai/src/chat.rs b/frontend/rust-lib/flowy-ai/src/chat.rs
index 5be2b7b014..a8655ff647 100644
--- a/frontend/rust-lib/flowy-ai/src/chat.rs
+++ b/frontend/rust-lib/flowy-ai/src/chat.rs
@@ -581,6 +581,7 @@ impl Chat {
author_type: record.author_type,
author_id: record.author_id,
reply_message_id: record.reply_message_id,
+ metadata: record.metadata,
})
.collect::<Vec<_>>();
@@ -641,7 +642,7 @@ fn save_chat_message_disk(
author_type: message.author.author_type as i64,
author_id: message.author.author_id.to_string(),
reply_message_id: message.reply_message_id,
- metadata: None,
+ metadata: Some(serde_json::to_string(&message.metadata).unwrap_or_default()),
})
.collect::<Vec<_>>();
insert_chat_messages(conn, &records)?;
diff --git a/frontend/rust-lib/flowy-ai/src/entities.rs b/frontend/rust-lib/flowy-ai/src/entities.rs
index d0cb7eda02..b62899eca3 100644
--- a/frontend/rust-lib/flowy-ai/src/entities.rs
+++ b/frontend/rust-lib/flowy-ai/src/entities.rs
@@ -296,6 +296,9 @@ pub struct ChatMessagePB {
#[pb(index = 6, one_of)]
pub reply_message_id: Option<i64>,
+
+ #[pb(index = 7, one_of)]
+ pub metadata: Option<String>,
}
#[derive(Debug, Clone, Default, ProtoBuf)]
@@ -316,6 +319,7 @@ impl From<ChatMessage> for ChatMessagePB {
author_type: chat_message.author.author_type as i64,
author_id: chat_message.author.author_id.to_string(),
reply_message_id: None,
+ metadata: Some(serde_json::to_string(&chat_message.metadata).unwrap_or_default()),
}
}
}
diff --git a/frontend/rust-lib/flowy-core/src/lib.rs b/frontend/rust-lib/flowy-core/src/lib.rs
index 31b98da5e6..21f09c1dad 100644
--- a/frontend/rust-lib/flowy-core/src/lib.rs
+++ b/frontend/rust-lib/flowy-core/src/lib.rs
@@ -35,6 +35,7 @@ use crate::deps_resolve::*;
use crate::log_filter::init_log;
use crate::server_layer::{current_server_type, Server, ServerProvider};
use deps_resolve::reminder_deps::CollabInteractImpl;
+use flowy_sqlite::DBConnection;
use user_state_callback::UserStatusCallbackImpl;
pub mod config;
@@ -334,4 +335,12 @@ impl ServerUser for ServerUserImpl {
fn workspace_id(&self) -> FlowyResult<Uuid> {
self.upgrade_user()?.workspace_id()
}
+
+ fn user_id(&self) -> FlowyResult<i64> {
+ self.upgrade_user()?.user_id()
+ }
+
+ fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError> {
+ self.upgrade_user()?.get_sqlite_connection(uid)
+ }
}
diff --git a/frontend/rust-lib/flowy-core/src/server_layer.rs b/frontend/rust-lib/flowy-core/src/server_layer.rs
index 0d304c6063..8157748b4f 100644
--- a/frontend/rust-lib/flowy-core/src/server_layer.rs
+++ b/frontend/rust-lib/flowy-core/src/server_layer.rs
@@ -1,15 +1,15 @@
use arc_swap::ArcSwapOption;
use dashmap::DashMap;
+use diesel::Connection;
+use serde_repr::*;
use std::fmt::{Display, Formatter};
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use std::sync::{Arc, Weak};
-use serde_repr::*;
-
use flowy_error::{FlowyError, FlowyResult};
use flowy_server::af_cloud::define::ServerUser;
use flowy_server::af_cloud::AppFlowyCloudServer;
-use flowy_server::local_server::{LocalServer, LocalServerDB};
+use flowy_server::local_server::LocalServer;
use flowy_server::{AppFlowyEncryption, AppFlowyServer, EncryptionImpl};
use flowy_server_pub::AuthenticatorType;
use flowy_sqlite::kv::KVStorePreferences;
@@ -115,10 +115,7 @@ impl ServerProvider {
let server = match server_type {
Server::Local => {
- let local_db = Arc::new(LocalServerDBImpl {
- storage_path: self.config.storage_path.clone(),
- });
- let server = Arc::new(LocalServer::new(local_db));
+ let server = Arc::new(LocalServer::new(self.user.clone()));
Ok::<Arc<dyn AppFlowyServer>, FlowyError>(server)
},
Server::AppFlowyCloud => {
@@ -171,24 +168,3 @@ pub fn current_server_type() -> Server {
AuthenticatorType::AppFlowyCloud => Server::AppFlowyCloud,
}
}
-
-struct LocalServerDBImpl {
- #[allow(dead_code)]
- storage_path: String,
-}
-
-impl LocalServerDB for LocalServerDBImpl {
- fn get_user_profile(&self, _uid: i64) -> Result<UserProfile, FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("LocalServer doesn't support get_user_profile"),
- )
- }
-
- fn get_user_workspace(&self, _uid: i64) -> Result<Option<UserWorkspace>, FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("LocalServer doesn't support get_user_workspace"),
- )
- }
-}
diff --git a/frontend/rust-lib/flowy-server/Cargo.toml b/frontend/rust-lib/flowy-server/Cargo.toml
index 9e67081eb7..e94570cc4a 100644
--- a/frontend/rust-lib/flowy-server/Cargo.toml
+++ b/frontend/rust-lib/flowy-server/Cargo.toml
@@ -12,20 +12,15 @@ crate-type = ["cdylib", "rlib"]
tracing.workspace = true
futures.workspace = true
futures-util = "0.3.26"
-reqwest = { version = "0.11.20", features = ["native-tls-vendored", "multipart", "blocking"] }
-hyper = "0.14"
serde.workspace = true
serde_json.workspace = true
thiserror = "1.0"
tokio = { workspace = true, features = ["sync"] }
lazy_static = "1.4.0"
bytes = { workspace = true, features = ["serde"] }
-tokio-retry = "0.3"
anyhow.workspace = true
arc-swap.workspace = true
-dashmap.workspace = true
uuid.workspace = true
-chrono = { workspace = true, default-features = false, features = ["clock", "serde"] }
collab = { workspace = true }
collab-plugins = { workspace = true }
collab-document = { workspace = true }
@@ -33,8 +28,6 @@ collab-entity = { workspace = true }
collab-folder = { workspace = true }
collab-database = { workspace = true }
collab-user = { workspace = true }
-hex = "0.4.3"
-postgrest = "1.0"
lib-infra = { workspace = true }
flowy-user-pub = { workspace = true }
flowy-folder-pub = { workspace = true }
@@ -46,14 +39,11 @@ flowy-search-pub = { workspace = true }
flowy-storage = { workspace = true }
flowy-storage-pub = { workspace = true }
flowy-ai-pub = { workspace = true }
-mime_guess = "2.0"
-url = "2.4"
tokio-util = "0.7"
tokio-stream = { workspace = true, features = ["sync"] }
-lib-dispatch = { workspace = true }
-yrs.workspace = true
rand = "0.8.5"
semver = "1.0.23"
+flowy-sqlite = { workspace = true }
[dependencies.client-api]
workspace = true
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/define.rs b/frontend/rust-lib/flowy-server/src/af_cloud/define.rs
index db75ea93fe..3b2895b8f8 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/define.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/define.rs
@@ -1,4 +1,5 @@
-use flowy_error::FlowyResult;
+use flowy_error::{FlowyError, FlowyResult};
+use flowy_sqlite::DBConnection;
use uuid::Uuid;
pub const USER_SIGN_IN_URL: &str = "sign_in_url";
@@ -10,4 +11,8 @@ pub const USER_DEVICE_ID: &str = "device_id";
pub trait ServerUser: Send + Sync {
/// different user might return different workspace id.
fn workspace_id(&self) -> FlowyResult<Uuid>;
+
+ fn user_id(&self) -> FlowyResult<i64>;
+
+ fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError>;
}
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
index e59166fc37..6d7d9d743b 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
@@ -378,10 +378,6 @@ where
Arc::into_inner(rx)
}
- async fn reset_workspace(&self, _collab_object: CollabObject) -> Result<(), FlowyError> {
- Ok(())
- }
-
async fn create_collab_object(
&self,
collab_object: &CollabObject,
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
index a68dbc8b4f..a6bfea53b4 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/chat.rs
@@ -1,3 +1,4 @@
+use crate::af_cloud::define::ServerUser;
use client_api::entity::ai_dto::{LocalAIConfig, RepeatedRelatedQuestion};
use flowy_ai_pub::cloud::{
AIModel, ChatCloudService, ChatMessage, ChatMessageMetadata, ChatMessageType, ChatSettings,
@@ -10,9 +11,12 @@ use lib_infra::util::timestamp;
use serde_json::Value;
use std::collections::HashMap;
use std::path::Path;
+use std::sync::Arc;
use uuid::Uuid;
-pub(crate) struct LocalServerChatServiceImpl;
+pub struct LocalServerChatServiceImpl {
+ pub user: Arc<dyn ServerUser>,
+}
#[async_trait]
impl ChatCloudService for LocalServerChatServiceImpl {
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
index 7bb3139953..bd2372e9d4 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/folder.rs
@@ -1,7 +1,6 @@
#![allow(unused_variables)]
use std::sync::Arc;
-use crate::local_server::LocalServerDB;
use client_api::entity::workspace_dto::PublishInfoView;
use client_api::entity::PublishInfo;
use collab_entity::CollabType;
@@ -14,10 +13,7 @@ use flowy_folder_pub::entities::PublishPayload;
use lib_infra::async_trait::async_trait;
use uuid::Uuid;
-pub(crate) struct LocalServerFolderCloudServiceImpl {
- #[allow(dead_code)]
- pub db: Arc<dyn LocalServerDB>,
-}
+pub(crate) struct LocalServerFolderCloudServiceImpl;
#[async_trait]
impl FolderCloudService for LocalServerFolderCloudServiceImpl {
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
index 8d9e342e85..df9050623e 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
@@ -18,24 +18,19 @@ use lib_infra::box_any::BoxAny;
use lib_infra::util::timestamp;
use crate::local_server::uid::UserIDGenerator;
-use crate::local_server::LocalServerDB;
lazy_static! {
//FIXME: seriously, userID generation should work using lock-free algorithm
static ref ID_GEN: Mutex<UserIDGenerator> = Mutex::new(UserIDGenerator::new(1));
}
-pub(crate) struct LocalServerUserAuthServiceImpl {
- #[allow(dead_code)]
- pub db: Arc<dyn LocalServerDB>,
-}
-
+pub(crate) struct LocalServerUserServiceImpl;
#[async_trait]
-impl UserCloudService for LocalServerUserAuthServiceImpl {
+impl UserCloudService for LocalServerUserServiceImpl {
async fn sign_up(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
let params = params.unbox_or_error::<SignUpParams>()?;
let uid = ID_GEN.lock().await.next_id();
- let workspace_id = uuid::Uuid::new_v4().to_string();
+ let workspace_id = Uuid::new_v4().to_string();
let user_workspace = UserWorkspace::new_local(&workspace_id, uid);
let user_name = if params.name.is_empty() {
DEFAULT_USER_NAME()
@@ -58,13 +53,9 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
}
async fn sign_in(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
- let db = self.db.clone();
let params: SignInParams = params.unbox_or_error::<SignInParams>()?;
let uid = ID_GEN.lock().await.next_id();
-
- let user_workspace = db
- .get_user_workspace(uid)?
- .unwrap_or_else(make_user_workspace);
+ let user_workspace = make_user_workspace();
Ok(AuthResponse {
user_id: uid,
user_uuid: Uuid::new_v4(),
@@ -132,16 +123,7 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
}
async fn get_user_profile(&self, credential: UserCredentials) -> Result<UserProfile, FlowyError> {
- match credential.uid {
- None => Err(FlowyError::record_not_found()),
- Some(uid) => {
- self.db.get_user_profile(uid).map(|mut profile| {
- // We don't want to expose the email in the local server
- profile.email = "".to_string();
- profile
- })
- },
- }
+ Err(FlowyError::local_version_not_support().with_context("Not support"))
}
async fn open_workspace(&self, workspace_id: &Uuid) -> Result<UserWorkspace, FlowyError> {
@@ -155,6 +137,32 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
Ok(vec![])
}
+ async fn create_workspace(&self, _workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
+ Err(
+ FlowyError::local_version_not_support()
+ .with_context("local server doesn't support multiple workspaces"),
+ )
+ }
+
+ async fn patch_workspace(
+ &self,
+ workspace_id: &Uuid,
+ new_workspace_name: Option<&str>,
+ new_workspace_icon: Option<&str>,
+ ) -> Result<(), FlowyError> {
+ Err(
+ FlowyError::local_version_not_support()
+ .with_context("local server doesn't support multiple workspaces"),
+ )
+ }
+
+ async fn delete_workspace(&self, workspace_id: &Uuid) -> Result<(), FlowyError> {
+ Err(
+ FlowyError::local_version_not_support()
+ .with_context("local server doesn't support multiple workspaces"),
+ )
+ }
+
async fn get_user_awareness_doc_state(
&self,
uid: i64,
@@ -172,10 +180,6 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
Ok(encode_collab.doc_state.to_vec())
}
- async fn reset_workspace(&self, _collab_object: CollabObject) -> Result<(), FlowyError> {
- Ok(())
- }
-
async fn create_collab_object(
&self,
_collab_object: &CollabObject,
@@ -194,32 +198,6 @@ impl UserCloudService for LocalServerUserAuthServiceImpl {
.with_context("local server doesn't support batch create collab object"),
)
}
-
- async fn create_workspace(&self, _workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("local server doesn't support multiple workspaces"),
- )
- }
-
- async fn delete_workspace(&self, workspace_id: &Uuid) -> Result<(), FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("local server doesn't support multiple workspaces"),
- )
- }
-
- async fn patch_workspace(
- &self,
- workspace_id: &Uuid,
- new_workspace_name: Option<&str>,
- new_workspace_icon: Option<&str>,
- ) -> Result<(), FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("local server doesn't support multiple workspaces"),
- )
- }
}
fn make_user_workspace() -> UserWorkspace {
diff --git a/frontend/rust-lib/flowy-server/src/local_server/server.rs b/frontend/rust-lib/flowy-server/src/local_server/server.rs
index 280a56cfe0..282d118203 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/server.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/server.rs
@@ -1,40 +1,30 @@
use flowy_search_pub::cloud::SearchCloudService;
use std::sync::Arc;
+use crate::af_cloud::define::ServerUser;
+use crate::local_server::impls::{
+ LocalServerChatServiceImpl, LocalServerDatabaseCloudServiceImpl,
+ LocalServerDocumentCloudServiceImpl, LocalServerFolderCloudServiceImpl,
+ LocalServerUserServiceImpl,
+};
+use crate::AppFlowyServer;
use flowy_ai_pub::cloud::ChatCloudService;
use flowy_database_pub::cloud::{DatabaseAIService, DatabaseCloudService};
use flowy_document_pub::cloud::DocumentCloudService;
-use flowy_error::FlowyError;
use flowy_folder_pub::cloud::FolderCloudService;
use flowy_storage_pub::cloud::StorageCloudService;
-use tokio::sync::mpsc;
-// use flowy_user::services::database::{
-// get_user_profile, get_user_workspace, open_collab_db, open_user_db,
-// };
use flowy_user_pub::cloud::UserCloudService;
-use flowy_user_pub::entities::*;
-
-use crate::local_server::impls::{
- LocalServerChatServiceImpl, LocalServerDatabaseCloudServiceImpl,
- LocalServerDocumentCloudServiceImpl, LocalServerFolderCloudServiceImpl,
- LocalServerUserAuthServiceImpl,
-};
-use crate::AppFlowyServer;
-
-pub trait LocalServerDB: Send + Sync + 'static {
- fn get_user_profile(&self, uid: i64) -> Result<UserProfile, FlowyError>;
- fn get_user_workspace(&self, uid: i64) -> Result<Option<UserWorkspace>, FlowyError>;
-}
+use tokio::sync::mpsc;
pub struct LocalServer {
- local_db: Arc<dyn LocalServerDB>,
+ user: Arc<dyn ServerUser>,
stop_tx: Option<mpsc::Sender<()>>,
}
impl LocalServer {
- pub fn new(local_db: Arc<dyn LocalServerDB>) -> Self {
+ pub fn new(user: Arc<dyn ServerUser>) -> Self {
Self {
- local_db,
+ user,
stop_tx: Default::default(),
}
}
@@ -49,38 +39,36 @@ impl LocalServer {
impl AppFlowyServer for LocalServer {
fn user_service(&self) -> Arc<dyn UserCloudService> {
- Arc::new(LocalServerUserAuthServiceImpl {
- db: self.local_db.clone(),
- })
+ Arc::new(LocalServerUserServiceImpl)
}
fn folder_service(&self) -> Arc<dyn FolderCloudService> {
- Arc::new(LocalServerFolderCloudServiceImpl {
- db: self.local_db.clone(),
- })
+ Arc::new(LocalServerFolderCloudServiceImpl)
}
fn database_service(&self) -> Arc<dyn DatabaseCloudService> {
Arc::new(LocalServerDatabaseCloudServiceImpl())
}
+ fn database_ai_service(&self) -> Option<Arc<dyn DatabaseAIService>> {
+ None
+ }
+
fn document_service(&self) -> Arc<dyn DocumentCloudService> {
Arc::new(LocalServerDocumentCloudServiceImpl())
}
- fn file_storage(&self) -> Option<Arc<dyn StorageCloudService>> {
- None
+ fn chat_service(&self) -> Arc<dyn ChatCloudService> {
+ Arc::new(LocalServerChatServiceImpl {
+ user: self.user.clone(),
+ })
}
fn search_service(&self) -> Option<Arc<dyn SearchCloudService>> {
None
}
- fn database_ai_service(&self) -> Option<Arc<dyn DatabaseAIService>> {
+ fn file_storage(&self) -> Option<Arc<dyn StorageCloudService>> {
None
}
-
- fn chat_service(&self) -> Arc<dyn ChatCloudService> {
- Arc::new(LocalServerChatServiceImpl)
- }
}
diff --git a/frontend/rust-lib/flowy-server/tests/af_cloud_test/util.rs b/frontend/rust-lib/flowy-server/tests/af_cloud_test/util.rs
index 9c88917df8..d00f484068 100644
--- a/frontend/rust-lib/flowy-server/tests/af_cloud_test/util.rs
+++ b/frontend/rust-lib/flowy-server/tests/af_cloud_test/util.rs
@@ -3,14 +3,14 @@ use semver::Version;
use std::collections::HashMap;
use std::sync::Arc;
-use flowy_error::FlowyResult;
+use flowy_error::{FlowyError, FlowyResult};
use uuid::Uuid;
+use crate::setup_log;
use flowy_server::af_cloud::define::ServerUser;
use flowy_server::af_cloud::AppFlowyCloudServer;
use flowy_server_pub::af_cloud_config::AFCloudConfiguration;
-
-use crate::setup_log;
+use flowy_sqlite::DBConnection;
/// To run the test, create a .env.ci file in the 'flowy-server' directory and set the following environment variables:
///
@@ -42,6 +42,14 @@ impl ServerUser for FakeServerUserImpl {
fn workspace_id(&self) -> FlowyResult<Uuid> {
todo!()
}
+
+ fn user_id(&self) -> FlowyResult<i64> {
+ todo!()
+ }
+
+ fn get_sqlite_db(&self, uid: i64) -> Result<DBConnection, FlowyError> {
+ todo!()
+ }
}
pub async fn generate_sign_in_url(user_email: &str, config: &AFCloudConfiguration) -> String {
diff --git a/frontend/rust-lib/flowy-user-pub/Cargo.toml b/frontend/rust-lib/flowy-user-pub/Cargo.toml
index 0228e25d35..80d087e88e 100644
--- a/frontend/rust-lib/flowy-user-pub/Cargo.toml
+++ b/frontend/rust-lib/flowy-user-pub/Cargo.toml
@@ -23,3 +23,4 @@ collab-folder = { workspace = true }
tracing.workspace = true
base64 = "0.21"
client-api = { workspace = true }
+arc-swap = "1.7.1"
diff --git a/frontend/rust-lib/flowy-user-pub/src/cloud.rs b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
index 3f7f39910b..dde94aebdc 100644
--- a/frontend/rust-lib/flowy-user-pub/src/cloud.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
@@ -263,8 +263,6 @@ pub trait UserCloudService: Send + Sync + 'static {
None
}
- async fn reset_workspace(&self, collab_object: CollabObject) -> Result<(), FlowyError>;
-
async fn create_collab_object(
&self,
collab_object: &CollabObject,
diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rs
index 85b9274df3..c0b7a8d6c2 100644
--- a/frontend/rust-lib/flowy-user/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs
@@ -614,24 +614,6 @@ pub async fn get_all_reminder_event_handler(
data_result_ok(reminders.into())
}
-#[tracing::instrument(level = "debug", skip_all, err)]
-pub async fn reset_workspace_handler(
- data: AFPluginData<ResetWorkspacePB>,
- manager: AFPluginState<Weak<UserManager>>,
-) -> Result<(), FlowyError> {
- let manager = upgrade_manager(manager)?;
- let reset_pb = data.into_inner();
- if reset_pb.workspace_id.is_empty() {
- return Err(FlowyError::new(
- ErrorCode::WorkspaceInitializeError,
- "The workspace id is empty",
- ));
- }
- let _session = manager.get_session()?;
- manager.reset_workspace(reset_pb).await?;
- Ok(())
-}
-
#[tracing::instrument(level = "debug", skip_all, err)]
pub async fn remove_reminder_event_handler(
data: AFPluginData<ReminderIdentifierPB>,
diff --git a/frontend/rust-lib/flowy-user/src/event_map.rs b/frontend/rust-lib/flowy-user/src/event_map.rs
index 2de1fdfbdc..7ed4948771 100644
--- a/frontend/rust-lib/flowy-user/src/event_map.rs
+++ b/frontend/rust-lib/flowy-user/src/event_map.rs
@@ -49,7 +49,6 @@ pub fn init(user_manager: Weak<UserManager>) -> AFPlugin {
.event(UserEvent::GetAllReminders, get_all_reminder_event_handler)
.event(UserEvent::RemoveReminder, remove_reminder_event_handler)
.event(UserEvent::UpdateReminder, update_reminder_event_handler)
- .event(UserEvent::ResetWorkspace, reset_workspace_handler)
.event(UserEvent::SetDateTimeSettings, set_date_time_settings)
.event(UserEvent::GetDateTimeSettings, get_date_time_settings)
.event(UserEvent::SetNotificationSettings, set_notification_settings)
@@ -183,9 +182,6 @@ pub enum UserEvent {
#[event(input = "ReminderPB")]
UpdateReminder = 31,
- #[event(input = "ResetWorkspacePB")]
- ResetWorkspace = 32,
-
/// Change the Date/Time formats globally
#[event(input = "DateTimeSettingsPB")]
SetDateTimeSettings = 33,
diff --git a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
index ab9a35b483..bc9603e26a 100644
--- a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
+++ b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
@@ -1,7 +1,6 @@
use crate::migrations::session_migration::migrate_session_with_user_uuid;
use crate::services::db::UserDB;
use crate::services::entities::{UserConfig, UserPaths};
-use crate::services::sqlite_sql::user_sql::vacuum_database;
use collab_integrate::CollabKVDB;
use arc_swap::ArcSwapOption;
@@ -18,8 +17,6 @@ use std::sync::{Arc, Weak};
use tracing::{error, info};
use uuid::Uuid;
-const SQLITE_VACUUM_042: &str = "sqlite_vacuum_042_version";
-
pub struct AuthenticateUser {
pub user_config: UserConfig,
pub(crate) database: Arc<UserDB>,
@@ -44,23 +41,6 @@ impl AuthenticateUser {
}
}
- pub fn vacuum_database_if_need(&self) {
- if !self
- .store_preferences
- .get_bool_or_default(SQLITE_VACUUM_042)
- {
- if let Ok(session) = self.get_session() {
- let _ = self.store_preferences.set_bool(SQLITE_VACUUM_042, true);
- if let Ok(conn) = self.database.get_connection(session.user_id) {
- info!("vacuum database 042");
- if let Err(err) = vacuum_database(conn) {
- error!("vacuum database error: {:?}", err);
- }
- }
- }
- }
- }
-
pub fn user_id(&self) -> FlowyResult<i64> {
let session = self.get_session()?;
Ok(session.user_id)
diff --git a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
index 6da6f183cb..c63764a055 100644
--- a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
+++ b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/user_sql.rs
@@ -148,10 +148,3 @@ pub fn select_user_profile(uid: i64, mut conn: DBConnection) -> Result<UserProfi
Ok(user)
}
-
-pub(crate) fn vacuum_database(mut conn: DBConnection) -> Result<(), FlowyError> {
- sql_query("VACUUM")
- .execute(&mut *conn)
- .map_err(internal_error)?;
- Ok(())
-}
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
index b4bc8911e1..5b5d060539 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
@@ -268,7 +268,6 @@ impl UserManager {
},
_ => error!("Failed to get collab db or sqlite pool"),
}
- self.authenticate_user.vacuum_database_if_need();
// migrations should run before set the first time installed version
self.set_first_time_installed_version();
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
index dae5a51ccc..2fff0c260b 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
@@ -414,24 +414,6 @@ impl UserManager {
Ok(workspaces)
}
- /// Reset the remote workspace using local workspace data. This is useful when a user wishes to
- /// open a workspace on a new device that hasn't fully synchronized with the server.
- pub async fn reset_workspace(&self, reset: ResetWorkspacePB) -> FlowyResult<()> {
- let collab_object = CollabObject::new(
- reset.uid,
- reset.workspace_id.clone(),
- CollabType::Folder,
- reset.workspace_id.clone(),
- self.authenticate_user.user_config.device_id.clone(),
- );
- self
- .cloud_services
- .get_user_service()?
- .reset_workspace(collab_object)
- .await?;
- Ok(())
- }
-
#[instrument(level = "info", skip(self), err)]
pub async fn subscribe_workspace(
&self,