From b1d87d95cf08c14d4ec4d69413b2dfbcdcad0157 Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 19 Mar 2022 16:23:34 +0800 Subject: [PATCH] chore: remove unuse crates --- .../flowy-error-code/code.pbenum.dart | 2 + .../flowy-error-code/code.pbjson.dart | 3 +- frontend/app_flowy/pubspec.lock | 2 +- frontend/rust-lib/Cargo.lock | 64 ------------------- frontend/rust-lib/Cargo.toml | 11 ++++ frontend/rust-lib/flowy-block/Cargo.toml | 7 +- .../rust-lib/flowy-block/tests/editor/mod.rs | 1 - frontend/rust-lib/flowy-folder/Cargo.toml | 11 ---- .../rust-lib/flowy-folder/src/event_map.rs | 6 +- frontend/rust-lib/flowy-folder/src/manager.rs | 5 +- .../src/services/persistence/mod.rs | 2 +- .../services/persistence/version_1/app_sql.rs | 44 ++----------- .../services/persistence/version_1/v1_impl.rs | 2 +- frontend/rust-lib/flowy-grid/Cargo.toml | 2 - frontend/rust-lib/flowy-grid/src/manager.rs | 10 +-- .../flowy-grid/src/services/kv_persistence.rs | 2 +- frontend/rust-lib/flowy-sync/Cargo.toml | 4 -- frontend/rust-lib/flowy-user/Cargo.toml | 16 ++--- frontend/rust-lib/flowy-user/src/lib.rs | 2 +- .../flowy-user/src/services/database.rs | 6 +- .../flowy-user/src/services/user_session.rs | 2 +- .../tests/event/user_profile_test.rs | 9 +-- shared-lib/flowy-error-code/src/code.rs | 3 + .../src/protobuf/model/code.rs | 42 ++++++------ .../src/protobuf/proto/code.proto | 1 + .../src/user_default.rs | 3 +- 26 files changed, 71 insertions(+), 191 deletions(-) diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbenum.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbenum.dart index 02e3e595c5..5e5da6665d 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbenum.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbenum.dart @@ -13,6 +13,7 @@ class ErrorCode extends $pb.ProtobufEnum { static const ErrorCode Internal = ErrorCode._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Internal'); static const ErrorCode UserUnauthorized = ErrorCode._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); static const ErrorCode RecordNotFound = ErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'RecordNotFound'); + static const ErrorCode UserIdIsEmpty = ErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdIsEmpty'); static const ErrorCode WorkspaceNameInvalid = ErrorCode._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceNameInvalid'); static const ErrorCode WorkspaceIdInvalid = ErrorCode._(101, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceIdInvalid'); static const ErrorCode AppColorStyleInvalid = ErrorCode._(102, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppColorStyleInvalid'); @@ -50,6 +51,7 @@ class ErrorCode extends $pb.ProtobufEnum { Internal, UserUnauthorized, RecordNotFound, + UserIdIsEmpty, WorkspaceNameInvalid, WorkspaceIdInvalid, AppColorStyleInvalid, diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbjson.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbjson.dart index 7a3269aa7f..7c18eb68e2 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbjson.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-error-code/code.pbjson.dart @@ -15,6 +15,7 @@ const ErrorCode$json = const { const {'1': 'Internal', '2': 0}, const {'1': 'UserUnauthorized', '2': 2}, const {'1': 'RecordNotFound', '2': 3}, + const {'1': 'UserIdIsEmpty', '2': 4}, const {'1': 'WorkspaceNameInvalid', '2': 100}, const {'1': 'WorkspaceIdInvalid', '2': 101}, const {'1': 'AppColorStyleInvalid', '2': 102}, @@ -51,4 +52,4 @@ const ErrorCode$json = const { }; /// Descriptor for `ErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSDAoISW50ZXJuYWwQABIUChBVc2VyVW5hdXRob3JpemVkEAISEgoOUmVjb3JkTm90Rm91bmQQAxIYChRXb3Jrc3BhY2VOYW1lSW52YWxpZBBkEhYKEldvcmtzcGFjZUlkSW52YWxpZBBlEhgKFEFwcENvbG9yU3R5bGVJbnZhbGlkEGYSGAoUV29ya3NwYWNlRGVzY1Rvb0xvbmcQZxIYChRXb3Jrc3BhY2VOYW1lVG9vTG9uZxBoEhAKDEFwcElkSW52YWxpZBBuEhIKDkFwcE5hbWVJbnZhbGlkEG8SEwoPVmlld05hbWVJbnZhbGlkEHgSGAoUVmlld1RodW1ibmFpbEludmFsaWQQeRIRCg1WaWV3SWRJbnZhbGlkEHoSEwoPVmlld0Rlc2NUb29Mb25nEHsSEwoPVmlld0RhdGFJbnZhbGlkEHwSEwoPVmlld05hbWVUb29Mb25nEH0SEQoMQ29ubmVjdEVycm9yEMgBEhEKDEVtYWlsSXNFbXB0eRCsAhIXChJFbWFpbEZvcm1hdEludmFsaWQQrQISFwoSRW1haWxBbHJlYWR5RXhpc3RzEK4CEhQKD1Bhc3N3b3JkSXNFbXB0eRCvAhIUCg9QYXNzd29yZFRvb0xvbmcQsAISJQogUGFzc3dvcmRDb250YWluc0ZvcmJpZENoYXJhY3RlcnMQsQISGgoVUGFzc3dvcmRGb3JtYXRJbnZhbGlkELICEhUKEFBhc3N3b3JkTm90TWF0Y2gQswISFAoPVXNlck5hbWVUb29Mb25nELQCEicKIlVzZXJOYW1lQ29udGFpbkZvcmJpZGRlbkNoYXJhY3RlcnMQtQISFAoPVXNlck5hbWVJc0VtcHR5ELYCEhIKDVVzZXJJZEludmFsaWQQtwISEQoMVXNlck5vdEV4aXN0ELgCEhAKC1RleHRUb29Mb25nEJADEhMKDkJsb2NrSWRJc0VtcHR5EJEDEhEKDFJvd0lkSXNFbXB0eRCSAxISCg1HcmlkSWRJc0VtcHR5EJMDEhAKC0ludmFsaWREYXRhEJQD'); +final $typed_data.Uint8List errorCodeDescriptor = $convert.base64Decode('CglFcnJvckNvZGUSDAoISW50ZXJuYWwQABIUChBVc2VyVW5hdXRob3JpemVkEAISEgoOUmVjb3JkTm90Rm91bmQQAxIRCg1Vc2VySWRJc0VtcHR5EAQSGAoUV29ya3NwYWNlTmFtZUludmFsaWQQZBIWChJXb3Jrc3BhY2VJZEludmFsaWQQZRIYChRBcHBDb2xvclN0eWxlSW52YWxpZBBmEhgKFFdvcmtzcGFjZURlc2NUb29Mb25nEGcSGAoUV29ya3NwYWNlTmFtZVRvb0xvbmcQaBIQCgxBcHBJZEludmFsaWQQbhISCg5BcHBOYW1lSW52YWxpZBBvEhMKD1ZpZXdOYW1lSW52YWxpZBB4EhgKFFZpZXdUaHVtYm5haWxJbnZhbGlkEHkSEQoNVmlld0lkSW52YWxpZBB6EhMKD1ZpZXdEZXNjVG9vTG9uZxB7EhMKD1ZpZXdEYXRhSW52YWxpZBB8EhMKD1ZpZXdOYW1lVG9vTG9uZxB9EhEKDENvbm5lY3RFcnJvchDIARIRCgxFbWFpbElzRW1wdHkQrAISFwoSRW1haWxGb3JtYXRJbnZhbGlkEK0CEhcKEkVtYWlsQWxyZWFkeUV4aXN0cxCuAhIUCg9QYXNzd29yZElzRW1wdHkQrwISFAoPUGFzc3dvcmRUb29Mb25nELACEiUKIFBhc3N3b3JkQ29udGFpbnNGb3JiaWRDaGFyYWN0ZXJzELECEhoKFVBhc3N3b3JkRm9ybWF0SW52YWxpZBCyAhIVChBQYXNzd29yZE5vdE1hdGNoELMCEhQKD1VzZXJOYW1lVG9vTG9uZxC0AhInCiJVc2VyTmFtZUNvbnRhaW5Gb3JiaWRkZW5DaGFyYWN0ZXJzELUCEhQKD1VzZXJOYW1lSXNFbXB0eRC2AhISCg1Vc2VySWRJbnZhbGlkELcCEhEKDFVzZXJOb3RFeGlzdBC4AhIQCgtUZXh0VG9vTG9uZxCQAxITCg5CbG9ja0lkSXNFbXB0eRCRAxIRCgxSb3dJZElzRW1wdHkQkgMSEgoNR3JpZElkSXNFbXB0eRCTAxIQCgtJbnZhbGlkRGF0YRCUAw=='); diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lock index 18bc260d4f..abd76b4448 100644 --- a/frontend/app_flowy/pubspec.lock +++ b/frontend/app_flowy/pubspec.lock @@ -1322,7 +1322,7 @@ packages: path: "plugins/window_size" ref: e48abe7c3e9ebfe0b81622167c5201d4e783bb81 resolved-ref: e48abe7c3e9ebfe0b81622167c5201d4e783bb81 - url: "git://github.com/google/flutter-desktop-embedding.git" + url: "https://github.com/google/flutter-desktop-embedding.git" source: git version: "0.1.0" xdg_directories: diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index 929fcad90c..27f3e9310e 100755 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -84,17 +84,6 @@ dependencies = [ "syn", ] -[[package]] -name = "async-trait" -version = "0.1.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "atomic" version = "0.5.1" @@ -464,20 +453,6 @@ dependencies = [ "itertools", ] -[[package]] -name = "crossbeam" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" -dependencies = [ - "cfg-if", - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils", -] - [[package]] name = "crossbeam-channel" version = "0.5.2" @@ -512,16 +487,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b979d76c9fcb84dffc80a73f7290da0f83e4c95773494674cb44b76d13a7a110" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.6" @@ -858,9 +823,6 @@ name = "flowy-block" version = "0.1.0" dependencies = [ "async-stream", - "async-trait", - "bytecount", - "byteorder", "bytes", "chrono", "color-eyre", @@ -884,8 +846,6 @@ dependencies = [ "lib-ot", "lib-ws", "log", - "parking_lot", - "pin-project", "protobuf", "rand 0.7.3", "serde", @@ -986,14 +946,8 @@ dependencies = [ name = "flowy-folder" version = "0.1.0" dependencies = [ - "bincode", "bytes", - "chrono", - "crossbeam", - "crossbeam-utils", "dart-notify", - "dashmap", - "derive_more", "diesel", "diesel_derives", "flowy-block", @@ -1006,19 +960,16 @@ dependencies = [ "flowy-sync", "flowy-test", "futures", - "futures-core", "lazy_static", "lib-dispatch", "lib-infra", "lib-ot", - "lib-sqlite", "log", "parking_lot", "pin-project", "protobuf", "serde", "serde_json", - "serial_test", "strum", "strum_macros", "tokio", @@ -1067,8 +1018,6 @@ dependencies = [ "lib-dispatch", "lib-infra", "lib-ot", - "lib-sqlite", - "parking_lot", "protobuf", "rayon", "rust_decimal", @@ -1171,7 +1120,6 @@ name = "flowy-sync" version = "0.1.0" dependencies = [ "async-stream", - "async-trait", "bytes", "dashmap", "diesel", @@ -1183,10 +1131,7 @@ dependencies = [ "lib-infra", "lib-ot", "lib-ws", - "parking_lot", - "protobuf", "serde", - "serde_json", "strum", "strum_macros", "tokio", @@ -1229,8 +1174,6 @@ version = "0.1.0" dependencies = [ "bytes", "dart-notify", - "dashmap", - "derive_more", "diesel", "diesel_derives", "flowy-database", @@ -1239,24 +1182,17 @@ dependencies = [ "flowy-test", "flowy-user-data-model", "futures", - "futures-core", "lazy_static", "lib-dispatch", "lib-infra", - "lib-sqlite", "log", "once_cell", "parking_lot", - "pin-project", "protobuf", - "r2d2", "serde", "serde_json", - "serial_test", "strum", "strum_macros", - "thread-id", - "thread_local", "tokio", "tracing", ] diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml index 84dcec26be..42f8187844 100644 --- a/frontend/rust-lib/Cargo.toml +++ b/frontend/rust-lib/Cargo.toml @@ -18,4 +18,15 @@ members = [ ] [profile.dev] +opt-level = 0 +#https://doc.rust-lang.org/rustc/codegen-options/index.html#debug-assertions split-debuginfo = "unpacked" + +[profile.release] +opt-level = 3 +## debuginfo — it makes ./target much bigger, which again harms caching. Depending on your preferred workflow, +## you might consider disabling debuginfo unconditionally, this brings some benefits for local builds as well. +#strip = "debuginfo" +## For from-scratch builds, incremental adds an extra dependency-tracking overhead. It also significantly increases +## the amount of IO and the size of ./target, which make caching less effective. +incremental = false \ No newline at end of file diff --git a/frontend/rust-lib/flowy-block/Cargo.toml b/frontend/rust-lib/flowy-block/Cargo.toml index 3973ff2c6c..b4ae85f597 100644 --- a/frontend/rust-lib/flowy-block/Cargo.toml +++ b/frontend/rust-lib/flowy-block/Cargo.toml @@ -13,7 +13,6 @@ lib-ot = { path = "../../../shared-lib/lib-ot" } lib-ws = { path = "../../../shared-lib/lib-ws" } lib-infra = { path = "../../../shared-lib/lib-infra" } -derive_more = {version = "0.99", features = ["display"]} lib-dispatch = { path = "../lib-dispatch" } flowy-database = { path = "../flowy-database" } flowy-sync = { path = "../flowy-sync" } @@ -31,22 +30,18 @@ bytes = { version = "1.1" } strum = "0.21" strum_macros = "0.21" dashmap = "4.0" -parking_lot = "0.11" -bytecount = "0.6.0" url = "2.2" serde = { version = "1.0", features = ["derive"] } serde_json = {version = "1.0"} chrono = "0.4.19" futures-util = "0.3.15" -byteorder = {version = "1.3.4"} async-stream = "0.3.2" -async-trait = "0.1.52" futures = "0.3.15" -pin-project = "1.0.0" [dev-dependencies] flowy-test = { path = "../flowy-test" } flowy-block = { path = "../flowy-block", features = ["flowy_unit_test"]} +derive_more = {version = "0.99", features = ["display"]} color-eyre = { version = "0.5", default-features = false } criterion = "0.3" diff --git a/frontend/rust-lib/flowy-block/tests/editor/mod.rs b/frontend/rust-lib/flowy-block/tests/editor/mod.rs index 64812b8d82..395629587e 100644 --- a/frontend/rust-lib/flowy-block/tests/editor/mod.rs +++ b/frontend/rust-lib/flowy-block/tests/editor/mod.rs @@ -4,7 +4,6 @@ mod op_test; mod serde_test; mod undo_redo_test; -use derive_more::Display; use flowy_collaboration::client_document::{ClientDocument, InitialDocumentText}; use lib_ot::{ core::*, diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml index 126b2828db..92e7b7b535 100644 --- a/frontend/rust-lib/flowy-folder/Cargo.toml +++ b/frontend/rust-lib/flowy-folder/Cargo.toml @@ -17,7 +17,6 @@ flowy-database = { path = "../flowy-database" } flowy-error = { path = "../flowy-error", features = ["db", "http_server"]} dart-notify = { path = "../dart-notify" } lib-dispatch = { path = "../lib-dispatch" } -lib-sqlite = { path = "../lib-sqlite" } flowy-sync = { path = "../flowy-sync" } parking_lot = "0.11" @@ -25,9 +24,6 @@ protobuf = {version = "2.18.0"} log = "0.4.14" diesel = {version = "1.4.8", features = ["sqlite"]} diesel_derives = {version = "1.4.1", features = ["sqlite"]} -#diesel = { git = "https://github.com/diesel-rs/diesel.git", branch = "master", features = ["sqlite"] } -#diesel_derives = { git = "https://github.com/diesel-rs/diesel.git", branch = "master",features = ["sqlite"] } -futures-core = { version = "0.3", default-features = false } futures = "0.3.15" pin-project = "1.0.0" strum = "0.21" @@ -35,17 +31,10 @@ strum_macros = "0.21" tokio = { version = "1", features = ["rt"] } lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"] } -derive_more = {version = "0.99", features = ["display"]} -bincode = { version = "1.3"} tracing = { version = "0.1", features = ["log"] } bytes = { version = "1.0" } -crossbeam = "0.8" -crossbeam-utils = "0.8" -chrono = "0.4" -dashmap = "4.0" [dev-dependencies] -serial_test = "0.5.1" serde_json = "1.0" flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]} flowy-test = { path = "../flowy-test" } diff --git a/frontend/rust-lib/flowy-folder/src/event_map.rs b/frontend/rust-lib/flowy-folder/src/event_map.rs index a470e289e5..906e9406ce 100644 --- a/frontend/rust-lib/flowy-folder/src/event_map.rs +++ b/frontend/rust-lib/flowy-folder/src/event_map.rs @@ -9,14 +9,12 @@ use crate::{ manager::FolderManager, services::{app::event_handler::*, trash::event_handler::*, view::event_handler::*, workspace::event_handler::*}, }; -use flowy_database::DBConnection; +use flowy_database::{ConnectionPool, DBConnection}; use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; -use strum_macros::Display; - use lib_dispatch::prelude::*; use lib_infra::future::FutureResult; -use lib_sqlite::ConnectionPool; use std::sync::Arc; +use strum_macros::Display; pub trait WorkspaceDeps: WorkspaceUser + WorkspaceDatabase {} diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs index 8fe34a2065..d93dca3f4e 100644 --- a/frontend/rust-lib/flowy-folder/src/manager.rs +++ b/frontend/rust-lib/flowy-folder/src/manager.rs @@ -9,8 +9,6 @@ use crate::{ }, }; use bytes::Bytes; -use chrono::Utc; - use flowy_collaboration::client_document::default::{initial_quill_delta_string, initial_read_me}; use flowy_collaboration::{client_folder::FolderPad, entities::ws_data::ServerRevisionWSData}; @@ -202,8 +200,7 @@ impl DefaultFolderBuilder { view_controller: Arc, ) -> FlowyResult<()> { log::debug!("Create user default workspace"); - let time = Utc::now(); - let workspace = user_default::create_default_workspace(time); + let workspace = user_default::create_default_workspace(); set_current_workspace(&workspace.id); for app in workspace.apps.iter() { for (index, view) in app.belongings.iter().enumerate() { diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs index 16417934e0..ccb35cc8ac 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/mod.rs @@ -9,6 +9,7 @@ use crate::{ }; use flowy_collaboration::client_folder::initial_folder_delta; use flowy_collaboration::{client_folder::FolderPad, entities::revision::Revision}; +use flowy_database::ConnectionPool; use flowy_error::{FlowyError, FlowyResult}; use flowy_folder_data_model::entities::{ app::App, @@ -18,7 +19,6 @@ use flowy_folder_data_model::entities::{ }; use flowy_sync::disk::{RevisionRecord, RevisionState}; use flowy_sync::mk_revision_disk_cache; -use lib_sqlite::ConnectionPool; use std::sync::Arc; use tokio::sync::RwLock; pub use version_1::{app_sql::*, trash_sql::*, v1_impl::V1Transaction, view_sql::*, workspace_sql::*}; diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs index 33b30a8656..46f351ff03 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs @@ -1,18 +1,14 @@ use crate::entities::{ - app::{App, ColorStyle, UpdateAppParams}, + app::{App, UpdateAppParams}, trash::{Trash, TrashType}, view::RepeatedView, }; -use diesel::sql_types::Binary; +use crate::{errors::FlowyError, services::persistence::version_1::workspace_sql::WorkspaceTable}; use flowy_database::{ prelude::*, schema::{app_table, app_table::dsl}, SqliteConnection, }; -use serde::{Deserialize, Serialize, __private::TryFrom}; -use std::convert::TryInto; - -use crate::{errors::FlowyError, services::persistence::version_1::workspace_sql::WorkspaceTable}; pub struct AppTableSql(); impl AppTableSql { @@ -86,7 +82,7 @@ pub(crate) struct AppTable { pub workspace_id: String, // equal to #[belongs_to(Workspace, foreign_key = "workspace_id")]. pub name: String, pub desc: String, - pub color_style: ColorStyleCol, + pub color_style: Vec, pub last_view_id: Option, pub modified_time: i64, pub create_time: i64, @@ -101,7 +97,7 @@ impl AppTable { workspace_id: app.workspace_id, name: app.name, desc: app.desc, - color_style: ColorStyleCol::default(), + color_style: Default::default(), last_view_id: None, modified_time: app.modified_time, create_time: app.create_time, @@ -123,38 +119,6 @@ impl std::convert::From for Trash { } } -#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, Default, FromSqlRow, AsExpression)] -#[sql_type = "Binary"] -pub(crate) struct ColorStyleCol { - pub(crate) theme_color: String, -} - -impl std::convert::From for ColorStyleCol { - fn from(s: ColorStyle) -> Self { - Self { - theme_color: s.theme_color, - } - } -} - -impl std::convert::TryInto> for &ColorStyleCol { - type Error = String; - - fn try_into(self) -> Result, Self::Error> { - bincode::serialize(self).map_err(|e| format!("{:?}", e)) - } -} - -impl std::convert::TryFrom<&[u8]> for ColorStyleCol { - type Error = String; - - fn try_from(value: &[u8]) -> Result { - bincode::deserialize(value).map_err(|e| format!("{:?}", e)) - } -} - -impl_sql_binary_expression!(ColorStyleCol); - #[derive(AsChangeset, Identifiable, Default, Debug)] #[table_name = "app_table"] pub struct AppChangeset { diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs index 847fc8225a..c301c5a972 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/v1_impl.rs @@ -6,6 +6,7 @@ use crate::services::persistence::{ }, FolderPersistenceTransaction, TrashTableSql, }; +use flowy_database::DBConnection; use flowy_error::FlowyResult; use flowy_folder_data_model::entities::{ app::App, @@ -13,7 +14,6 @@ use flowy_folder_data_model::entities::{ view::View, workspace::Workspace, }; -use lib_sqlite::DBConnection; pub struct V1Transaction<'a>(pub &'a DBConnection); diff --git a/frontend/rust-lib/flowy-grid/Cargo.toml b/frontend/rust-lib/flowy-grid/Cargo.toml index fda64c7f66..599f41c043 100644 --- a/frontend/rust-lib/flowy-grid/Cargo.toml +++ b/frontend/rust-lib/flowy-grid/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] lib-dispatch = { path = "../lib-dispatch" } dart-notify = { path = "../dart-notify" } -lib-sqlite = { path = "../lib-sqlite" } flowy-sync = { path = "../flowy-sync" } flowy-error = { path = "../flowy-error", features = ["db"]} flowy-derive = { path = "../../../shared-lib/flowy-derive" } @@ -32,7 +31,6 @@ diesel = {version = "1.4.8", features = ["sqlite"]} dashmap = "4.0" tokio = {version = "1", features = ["sync"]} rayon = "1.5" -parking_lot = "0.11" serde = { version = "1.0", features = ["derive"] } serde_json = {version = "1.0"} diff --git a/frontend/rust-lib/flowy-grid/src/manager.rs b/frontend/rust-lib/flowy-grid/src/manager.rs index 104f74d5f4..b0c1e16623 100644 --- a/frontend/rust-lib/flowy-grid/src/manager.rs +++ b/frontend/rust-lib/flowy-grid/src/manager.rs @@ -4,13 +4,13 @@ use bytes::Bytes; use dashmap::DashMap; use flowy_collaboration::client_grid::{make_block_meta_delta, make_grid_delta}; use flowy_collaboration::entities::revision::{RepeatedRevision, Revision}; +use flowy_database::ConnectionPool; use flowy_error::{FlowyError, FlowyResult}; use flowy_grid_data_model::entities::{BuildGridContext, GridMeta}; use flowy_sync::disk::{SQLiteGridBlockMetaRevisionPersistence, SQLiteGridRevisionPersistence}; use flowy_sync::{RevisionManager, RevisionPersistence, RevisionWebSocket}; -use lib_sqlite::ConnectionPool; -use parking_lot::RwLock; use std::sync::Arc; +use tokio::sync::RwLock; pub trait GridUser: Send + Sync { fn user_id(&self) -> Result; @@ -137,8 +137,8 @@ impl GridManager { } #[allow(dead_code)] - fn get_kv_persistence(&self) -> FlowyResult> { - let read_guard = self.kv_persistence.read(); + async fn get_kv_persistence(&self) -> FlowyResult> { + let read_guard = self.kv_persistence.read().await; if read_guard.is_some() { return Ok(read_guard.clone().unwrap()); } @@ -146,7 +146,7 @@ impl GridManager { let pool = self.grid_user.db_pool()?; let kv_persistence = Arc::new(GridKVPersistence::new(pool)); - *self.kv_persistence.write() = Some(kv_persistence.clone()); + *self.kv_persistence.write().await = Some(kv_persistence.clone()); Ok(kv_persistence) } } diff --git a/frontend/rust-lib/flowy-grid/src/services/kv_persistence.rs b/frontend/rust-lib/flowy-grid/src/services/kv_persistence.rs index 6577c52ecd..89961ace48 100644 --- a/frontend/rust-lib/flowy-grid/src/services/kv_persistence.rs +++ b/frontend/rust-lib/flowy-grid/src/services/kv_persistence.rs @@ -4,9 +4,9 @@ use diesel::SqliteConnection; use flowy_database::{ prelude::*, schema::{kv_table, kv_table::dsl}, + ConnectionPool, }; use flowy_error::{FlowyError, FlowyResult}; -use lib_sqlite::ConnectionPool; use std::sync::Arc; #[derive(PartialEq, Clone, Debug, Queryable, Identifiable, Insertable, Associations)] diff --git a/frontend/rust-lib/flowy-sync/Cargo.toml b/frontend/rust-lib/flowy-sync/Cargo.toml index 0d7476eda3..42e43826ba 100644 --- a/frontend/rust-lib/flowy-sync/Cargo.toml +++ b/frontend/rust-lib/flowy-sync/Cargo.toml @@ -14,19 +14,15 @@ flowy-database = { path = "../flowy-database" } flowy-error = { path = "../flowy-error", features = ["collaboration", "ot", "http_server", "serde", "db"] } diesel = {version = "1.4.8", features = ["sqlite"]} diesel_derives = {version = "1.4.1", features = ["sqlite"]} -protobuf = {version = "2.18.0"} tracing = { version = "0.1", features = ["log"] } tokio = {version = "1", features = ["sync"]} bytes = { version = "1.1" } strum = "0.21" strum_macros = "0.21" dashmap = "4.0" -parking_lot = "0.11" serde = { version = "1.0", features = ["derive"] } -serde_json = {version = "1.0"} futures-util = "0.3.15" async-stream = "0.3.2" -async-trait = "0.1.52" [features] flowy_unit_test = ["lib-ot/flowy_unit_test"] \ No newline at end of file diff --git a/frontend/rust-lib/flowy-user/Cargo.toml b/frontend/rust-lib/flowy-user/Cargo.toml index 307c59d62c..528b10b6e3 100644 --- a/frontend/rust-lib/flowy-user/Cargo.toml +++ b/frontend/rust-lib/flowy-user/Cargo.toml @@ -8,14 +8,12 @@ edition = "2018" [dependencies] flowy-user-data-model = { path = "../../../shared-lib/flowy-user-data-model" } flowy-derive = { path = "../../../shared-lib/flowy-derive" } -lib-infra = { path = "../../../shared-lib/lib-infra" } - -derive_more = {version = "0.99", features = ["display"]} flowy-database = { path = "../flowy-database" } +flowy-error = { path = "../flowy-error", features = ["db", "http_server"] } + +lib-infra = { path = "../../../shared-lib/lib-infra" } dart-notify = { path = "../dart-notify" } lib-dispatch = { path = "../lib-dispatch" } -flowy-error = { path = "../flowy-error", features = ["db", "http_server"] } -lib-sqlite = { path = "../lib-sqlite" } tracing = { version = "0.1", features = ["log"] } bytes = "1.0" @@ -26,22 +24,16 @@ protobuf = {version = "2.18.0"} lazy_static = "1.4.0" diesel = {version = "1.4.8", features = ["sqlite"]} diesel_derives = {version = "1.4.1", features = ["sqlite"]} -thread_local = "1.1.3" -thread-id = "3.3.0" once_cell = "1.7.2" parking_lot = "0.11" strum = "0.21" strum_macros = "0.21" tokio = { version = "1", features = ["rt"] } -pin-project = "1.0.0" -futures-core = { version = "0.3", default-features = false } -r2d2 = "0.8.9" -dashmap = "4.0" + [dev-dependencies] flowy-test = { path = "../flowy-test" } futures = "0.3.15" -serial_test = "0.5.1" [features] http_server = [] diff --git a/frontend/rust-lib/flowy-user/src/lib.rs b/frontend/rust-lib/flowy-user/src/lib.rs index 6d55e0c32f..18ef8e72e0 100644 --- a/frontend/rust-lib/flowy-user/src/lib.rs +++ b/frontend/rust-lib/flowy-user/src/lib.rs @@ -9,7 +9,7 @@ pub mod services; extern crate flowy_database; pub mod errors { - pub use flowy_error::{internal_error, ErrorCode, FlowyError}; + pub use flowy_error::*; } pub mod entities { diff --git a/frontend/rust-lib/flowy-user/src/services/database.rs b/frontend/rust-lib/flowy-user/src/services/database.rs index f7a8e9a85c..1229d6fba5 100644 --- a/frontend/rust-lib/flowy-user/src/services/database.rs +++ b/frontend/rust-lib/flowy-user/src/services/database.rs @@ -1,8 +1,8 @@ +use flowy_database::ConnectionPool; use flowy_database::{schema::user_table, DBConnection, Database}; -use flowy_error::FlowyError; +use flowy_error::{ErrorCode, FlowyError}; use flowy_user_data_model::entities::{SignInResponse, SignUpResponse, UpdateUserParams, UserProfile}; use lazy_static::lazy_static; -use lib_sqlite::ConnectionPool; use once_cell::sync::Lazy; use parking_lot::{Mutex, RwLock}; use std::{collections::HashMap, sync::Arc, time::Duration}; @@ -24,7 +24,7 @@ impl UserDB { fn open_user_db(&self, user_id: &str) -> Result<(), FlowyError> { if user_id.is_empty() { - return Err(FlowyError::internal().context("user id is empty")); + return Err(ErrorCode::UserIdIsEmpty.into()); } tracing::info!("open user db {}", user_id); diff --git a/frontend/rust-lib/flowy-user/src/services/user_session.rs b/frontend/rust-lib/flowy-user/src/services/user_session.rs index d8657ad01a..05eea59f87 100644 --- a/frontend/rust-lib/flowy-user/src/services/user_session.rs +++ b/frontend/rust-lib/flowy-user/src/services/user_session.rs @@ -7,6 +7,7 @@ use crate::{ notifier::UserNotifier, }, }; +use flowy_database::ConnectionPool; use flowy_database::{ kv::KV, query_dsl::*, @@ -16,7 +17,6 @@ use flowy_database::{ use flowy_user_data_model::entities::{ SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile, }; -use lib_sqlite::ConnectionPool; use parking_lot::RwLock; use serde::{Deserialize, Serialize}; use std::sync::Arc; diff --git a/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs b/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs index c74746090f..a109399c88 100644 --- a/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs +++ b/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs @@ -3,7 +3,7 @@ use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest}; use flowy_user::{errors::ErrorCode, event_map::UserEvent::*}; use flowy_user_data_model::entities::{UpdateUserPayload, UserProfile}; use lib_infra::uuid; -use serial_test::*; +// use serial_test::*; #[tokio::test] async fn user_profile_get_failed() { @@ -17,7 +17,6 @@ async fn user_profile_get_failed() { } #[tokio::test] -#[serial] async fn user_profile_get() { let test = FlowySDKTest::default(); let user_profile = test.init_user().await; @@ -29,7 +28,6 @@ async fn user_profile_get() { } #[tokio::test] -#[serial] async fn user_update_with_name() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; @@ -50,7 +48,6 @@ async fn user_update_with_name() { } #[tokio::test] -#[serial] async fn user_update_with_email() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; @@ -70,7 +67,6 @@ async fn user_update_with_email() { } #[tokio::test] -#[serial] async fn user_update_with_password() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; @@ -85,7 +81,6 @@ async fn user_update_with_password() { } #[tokio::test] -#[serial] async fn user_update_with_invalid_email() { let test = FlowySDKTest::default(); let user = test.init_user().await; @@ -104,7 +99,6 @@ async fn user_update_with_invalid_email() { } #[tokio::test] -#[serial] async fn user_update_with_invalid_password() { let test = FlowySDKTest::default(); let user = test.init_user().await; @@ -120,7 +114,6 @@ async fn user_update_with_invalid_password() { } #[tokio::test] -#[serial] async fn user_update_with_invalid_name() { let test = FlowySDKTest::default(); let user = test.init_user().await; diff --git a/shared-lib/flowy-error-code/src/code.rs b/shared-lib/flowy-error-code/src/code.rs index e184fd41bf..bccc0fefd9 100644 --- a/shared-lib/flowy-error-code/src/code.rs +++ b/shared-lib/flowy-error-code/src/code.rs @@ -15,6 +15,9 @@ pub enum ErrorCode { #[display(fmt = "RecordNotFound")] RecordNotFound = 3, + #[display(fmt = "User id is empty")] + UserIdIsEmpty = 4, + #[display(fmt = "Workspace name can not be empty or whitespace")] WorkspaceNameInvalid = 100, diff --git a/shared-lib/flowy-error-code/src/protobuf/model/code.rs b/shared-lib/flowy-error-code/src/protobuf/model/code.rs index 85a0721d7c..63a645ea6c 100644 --- a/shared-lib/flowy-error-code/src/protobuf/model/code.rs +++ b/shared-lib/flowy-error-code/src/protobuf/model/code.rs @@ -28,6 +28,7 @@ pub enum ErrorCode { Internal = 0, UserUnauthorized = 2, RecordNotFound = 3, + UserIdIsEmpty = 4, WorkspaceNameInvalid = 100, WorkspaceIdInvalid = 101, AppColorStyleInvalid = 102, @@ -72,6 +73,7 @@ impl ::protobuf::ProtobufEnum for ErrorCode { 0 => ::std::option::Option::Some(ErrorCode::Internal), 2 => ::std::option::Option::Some(ErrorCode::UserUnauthorized), 3 => ::std::option::Option::Some(ErrorCode::RecordNotFound), + 4 => ::std::option::Option::Some(ErrorCode::UserIdIsEmpty), 100 => ::std::option::Option::Some(ErrorCode::WorkspaceNameInvalid), 101 => ::std::option::Option::Some(ErrorCode::WorkspaceIdInvalid), 102 => ::std::option::Option::Some(ErrorCode::AppColorStyleInvalid), @@ -113,6 +115,7 @@ impl ::protobuf::ProtobufEnum for ErrorCode { ErrorCode::Internal, ErrorCode::UserUnauthorized, ErrorCode::RecordNotFound, + ErrorCode::UserIdIsEmpty, ErrorCode::WorkspaceNameInvalid, ErrorCode::WorkspaceIdInvalid, ErrorCode::AppColorStyleInvalid, @@ -173,26 +176,27 @@ impl ::protobuf::reflect::ProtobufValue for ErrorCode { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\ncode.proto*\xa4\x06\n\tErrorCode\x12\x0c\n\x08Internal\x10\0\x12\x14\ + \n\ncode.proto*\xb7\x06\n\tErrorCode\x12\x0c\n\x08Internal\x10\0\x12\x14\ \n\x10UserUnauthorized\x10\x02\x12\x12\n\x0eRecordNotFound\x10\x03\x12\ - \x18\n\x14WorkspaceNameInvalid\x10d\x12\x16\n\x12WorkspaceIdInvalid\x10e\ - \x12\x18\n\x14AppColorStyleInvalid\x10f\x12\x18\n\x14WorkspaceDescTooLon\ - g\x10g\x12\x18\n\x14WorkspaceNameTooLong\x10h\x12\x10\n\x0cAppIdInvalid\ - \x10n\x12\x12\n\x0eAppNameInvalid\x10o\x12\x13\n\x0fViewNameInvalid\x10x\ - \x12\x18\n\x14ViewThumbnailInvalid\x10y\x12\x11\n\rViewIdInvalid\x10z\ - \x12\x13\n\x0fViewDescTooLong\x10{\x12\x13\n\x0fViewDataInvalid\x10|\x12\ - \x13\n\x0fViewNameTooLong\x10}\x12\x11\n\x0cConnectError\x10\xc8\x01\x12\ - \x11\n\x0cEmailIsEmpty\x10\xac\x02\x12\x17\n\x12EmailFormatInvalid\x10\ - \xad\x02\x12\x17\n\x12EmailAlreadyExists\x10\xae\x02\x12\x14\n\x0fPasswo\ - rdIsEmpty\x10\xaf\x02\x12\x14\n\x0fPasswordTooLong\x10\xb0\x02\x12%\n\ - \x20PasswordContainsForbidCharacters\x10\xb1\x02\x12\x1a\n\x15PasswordFo\ - rmatInvalid\x10\xb2\x02\x12\x15\n\x10PasswordNotMatch\x10\xb3\x02\x12\ - \x14\n\x0fUserNameTooLong\x10\xb4\x02\x12'\n\"UserNameContainForbiddenCh\ - aracters\x10\xb5\x02\x12\x14\n\x0fUserNameIsEmpty\x10\xb6\x02\x12\x12\n\ - \rUserIdInvalid\x10\xb7\x02\x12\x11\n\x0cUserNotExist\x10\xb8\x02\x12\ - \x10\n\x0bTextTooLong\x10\x90\x03\x12\x13\n\x0eBlockIdIsEmpty\x10\x91\ - \x03\x12\x11\n\x0cRowIdIsEmpty\x10\x92\x03\x12\x12\n\rGridIdIsEmpty\x10\ - \x93\x03\x12\x10\n\x0bInvalidData\x10\x94\x03b\x06proto3\ + \x11\n\rUserIdIsEmpty\x10\x04\x12\x18\n\x14WorkspaceNameInvalid\x10d\x12\ + \x16\n\x12WorkspaceIdInvalid\x10e\x12\x18\n\x14AppColorStyleInvalid\x10f\ + \x12\x18\n\x14WorkspaceDescTooLong\x10g\x12\x18\n\x14WorkspaceNameTooLon\ + g\x10h\x12\x10\n\x0cAppIdInvalid\x10n\x12\x12\n\x0eAppNameInvalid\x10o\ + \x12\x13\n\x0fViewNameInvalid\x10x\x12\x18\n\x14ViewThumbnailInvalid\x10\ + y\x12\x11\n\rViewIdInvalid\x10z\x12\x13\n\x0fViewDescTooLong\x10{\x12\ + \x13\n\x0fViewDataInvalid\x10|\x12\x13\n\x0fViewNameTooLong\x10}\x12\x11\ + \n\x0cConnectError\x10\xc8\x01\x12\x11\n\x0cEmailIsEmpty\x10\xac\x02\x12\ + \x17\n\x12EmailFormatInvalid\x10\xad\x02\x12\x17\n\x12EmailAlreadyExists\ + \x10\xae\x02\x12\x14\n\x0fPasswordIsEmpty\x10\xaf\x02\x12\x14\n\x0fPassw\ + ordTooLong\x10\xb0\x02\x12%\n\x20PasswordContainsForbidCharacters\x10\ + \xb1\x02\x12\x1a\n\x15PasswordFormatInvalid\x10\xb2\x02\x12\x15\n\x10Pas\ + swordNotMatch\x10\xb3\x02\x12\x14\n\x0fUserNameTooLong\x10\xb4\x02\x12'\ + \n\"UserNameContainForbiddenCharacters\x10\xb5\x02\x12\x14\n\x0fUserName\ + IsEmpty\x10\xb6\x02\x12\x12\n\rUserIdInvalid\x10\xb7\x02\x12\x11\n\x0cUs\ + erNotExist\x10\xb8\x02\x12\x10\n\x0bTextTooLong\x10\x90\x03\x12\x13\n\ + \x0eBlockIdIsEmpty\x10\x91\x03\x12\x11\n\x0cRowIdIsEmpty\x10\x92\x03\x12\ + \x12\n\rGridIdIsEmpty\x10\x93\x03\x12\x10\n\x0bInvalidData\x10\x94\x03b\ + \x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/shared-lib/flowy-error-code/src/protobuf/proto/code.proto b/shared-lib/flowy-error-code/src/protobuf/proto/code.proto index 7015c1fe38..f8b8acb8e6 100644 --- a/shared-lib/flowy-error-code/src/protobuf/proto/code.proto +++ b/shared-lib/flowy-error-code/src/protobuf/proto/code.proto @@ -4,6 +4,7 @@ enum ErrorCode { Internal = 0; UserUnauthorized = 2; RecordNotFound = 3; + UserIdIsEmpty = 4; WorkspaceNameInvalid = 100; WorkspaceIdInvalid = 101; AppColorStyleInvalid = 102; diff --git a/shared-lib/flowy-folder-data-model/src/user_default.rs b/shared-lib/flowy-folder-data-model/src/user_default.rs index ff3161d89b..8b06c1d69b 100644 --- a/shared-lib/flowy-folder-data-model/src/user_default.rs +++ b/shared-lib/flowy-folder-data-model/src/user_default.rs @@ -5,7 +5,8 @@ use crate::entities::{ }; use chrono::Utc; -pub fn create_default_workspace(time: chrono::DateTime) -> Workspace { +pub fn create_default_workspace() -> Workspace { + let time = Utc::now(); let workspace_id = uuid::Uuid::new_v4(); let name = "Workspace".to_string(); let desc = "".to_string();