diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.lock b/frontend/appflowy_tauri/src-tauri/Cargo.lock index 7d24f77e2b..50f3914a2b 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.lock +++ b/frontend/appflowy_tauri/src-tauri/Cargo.lock @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -989,7 +989,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-trait", @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -1038,7 +1038,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "bytes", @@ -1057,7 +1057,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-stream", @@ -1180,7 +1180,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "collab", diff --git a/frontend/appflowy_tauri/src-tauri/Cargo.toml b/frontend/appflowy_tauri/src-tauri/Cargo.toml index 13e617e0a9..59591a566d 100644 --- a/frontend/appflowy_tauri/src-tauri/Cargo.toml +++ b/frontend/appflowy_tauri/src-tauri/Cargo.toml @@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"] # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.lock b/frontend/appflowy_web_app/src-tauri/Cargo.lock index 2a0be37d9b..cddb658ede 100644 --- a/frontend/appflowy_web_app/src-tauri/Cargo.lock +++ b/frontend/appflowy_web_app/src-tauri/Cargo.lock @@ -947,7 +947,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -972,7 +972,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-trait", @@ -1001,7 +1001,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -1021,7 +1021,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "bytes", @@ -1040,7 +1040,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -1083,7 +1083,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-stream", @@ -1163,7 +1163,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "collab", diff --git a/frontend/appflowy_web_app/src-tauri/Cargo.toml b/frontend/appflowy_web_app/src-tauri/Cargo.toml index 970787869a..22c8b60bfb 100644 --- a/frontend/appflowy_web_app/src-tauri/Cargo.toml +++ b/frontend/appflowy_web_app/src-tauri/Cargo.toml @@ -116,13 +116,13 @@ custom-protocol = ["tauri/custom-protocol"] # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index e804a9cbda..a85601a96e 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -825,7 +825,7 @@ dependencies = [ [[package]] name = "collab" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -850,7 +850,7 @@ dependencies = [ [[package]] name = "collab-database" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-trait", @@ -879,7 +879,7 @@ dependencies = [ [[package]] name = "collab-document" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -899,7 +899,7 @@ dependencies = [ [[package]] name = "collab-entity" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "bytes", @@ -918,7 +918,7 @@ dependencies = [ [[package]] name = "collab-folder" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "arc-swap", @@ -961,7 +961,7 @@ dependencies = [ [[package]] name = "collab-plugins" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "async-stream", @@ -1041,7 +1041,7 @@ dependencies = [ [[package]] name = "collab-user" version = "0.2.0" -source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d#0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" +source = "git+https://github.com/AppFlowy-IO/AppFlowy-Collab?rev=f747496df74b61bccfa25eaefae161a331f71f96#f747496df74b61bccfa25eaefae161a331f71f96" dependencies = [ "anyhow", "collab", diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.toml index 190808fa22..00735eaa35 100644 --- a/frontend/rust-lib/Cargo.toml +++ b/frontend/rust-lib/Cargo.toml @@ -136,13 +136,13 @@ rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1710120 # To switch to the local path, run: # scripts/tool/update_collab_source.sh # ⚠️⚠️⚠️️ -collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } -collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0b9abf42a4888b3b1789cfa68d2d1dbe9cb7e10d" } +collab = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-entity = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-folder = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-document = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-database = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-plugins = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } +collab-user = { version = "0.2", git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "f747496df74b61bccfa25eaefae161a331f71f96" } # Working directory: frontend # To update the commit ID, run: diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs index d3fb57a5d5..48b018fbfd 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs @@ -464,7 +464,7 @@ impl DatabaseEditor { new_field_type, old_type_option_data, new_type_option_data, - &database, + &mut database, ) .await; @@ -1362,6 +1362,21 @@ impl DatabaseEditor { let opening_database_views = self.database_views.clone(); tokio::spawn(async move { const CHUNK_SIZE: usize = 10; + let apply_filter_and_sort = + |mut loaded_rows, opening_database_views: Arc| async move { + for database_view in opening_database_views.editors().await { + if database_view.has_filters().await { + database_view + .v_filter_rows_and_notify(&mut loaded_rows) + .await; + } + + if database_view.has_sorts().await { + database_view.v_sort_rows_and_notify(&mut loaded_rows).await; + } + } + }; + let mut loaded_rows = vec![]; for chunk_row_orders in cloned_row_orders.chunks(CHUNK_SIZE) { match cloned_database.upgrade() { @@ -1382,23 +1397,15 @@ impl DatabaseEditor { return; } - if loaded_rows.len() % 100 == 0 { - for database_view in opening_database_views.editors().await { - let mut view_rows = loaded_rows.clone(); - database_view.v_filter_rows_and_notify(&mut view_rows).await; - database_view.v_sort_rows_and_notify(&mut view_rows).await; - } + if loaded_rows.len() % 1000 == 0 { + apply_filter_and_sort(loaded_rows.clone(), opening_database_views.clone()).await; } }, } tokio::task::yield_now().await; } - for database_view in opening_database_views.editors().await { - let mut view_rows = loaded_rows.clone(); - database_view.v_filter_rows_and_notify(&mut view_rows).await; - database_view.v_sort_rows_and_notify(&mut view_rows).await; - } + apply_filter_and_sort(loaded_rows.clone(), opening_database_views).await; }); // Collect database details in a single block holding the `read` lock diff --git a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs index 414abecae7..5697892a40 100644 --- a/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs +++ b/frontend/rust-lib/flowy-database2/src/services/database_view/view_editor.rs @@ -124,6 +124,14 @@ impl DatabaseViewEditor { self.calculations_controller.close().await; } + pub async fn has_filters(&self) -> bool { + self.filter_controller.has_filters().await + } + + pub async fn has_sorts(&self) -> bool { + self.sort_controller.read().await.has_sorts().await + } + pub async fn v_get_view(&self) -> Option { self.delegate.get_view(&self.view_id).await } diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_option_transform.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_option_transform.rs index 4bb2827310..f273c784e8 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_option_transform.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_option_transform.rs @@ -17,7 +17,7 @@ pub async fn transform_type_option( new_field_type: FieldType, old_type_option_data: Option, new_type_option_data: TypeOptionData, - database: &Database, + database: &mut Database, ) -> TypeOptionData { if let Some(old_type_option_data) = old_type_option_data { let mut transform_handler = @@ -28,6 +28,7 @@ pub async fn transform_type_option( field_id, old_field_type, old_type_option_data, + new_field_type, database, ) .await; @@ -46,7 +47,8 @@ pub trait TypeOptionTransformHandler: Send + Sync { field_id: &str, old_type_option_field_type: FieldType, old_type_option_data: TypeOptionData, - database: &Database, + new_type_option_field_type: FieldType, + database: &mut Database, ); fn to_type_option_data(&self) -> TypeOptionData; @@ -63,7 +65,8 @@ where field_id: &str, old_type_option_field_type: FieldType, old_type_option_data: TypeOptionData, - database: &Database, + new_type_option_field_type: FieldType, + database: &mut Database, ) { self .transform_type_option( @@ -71,6 +74,7 @@ where field_id, old_type_option_field_type, old_type_option_data, + new_type_option_field_type, database, ) .await diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs index 3eaf117f4d..ad51716310 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/date_type_option/date_type_option.rs @@ -1,16 +1,17 @@ -use std::cmp::Ordering; -use std::str::FromStr; - +use async_trait::async_trait; use chrono::{DateTime, FixedOffset, Local, NaiveDateTime, NaiveTime, Offset, TimeZone}; use chrono_tz::Tz; use collab::preclude::Any; use collab::util::AnyMapExt; +use collab_database::database::Database; use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder}; use collab_database::rows::Cell; use collab_database::template::date_parse::cast_string_to_timestamp; -use serde::{Deserialize, Serialize}; - use flowy_error::{ErrorCode, FlowyError, FlowyResult}; +use serde::{Deserialize, Serialize}; +use std::cmp::Ordering; +use std::str::FromStr; +use tracing::info; use crate::entities::{DateCellDataPB, DateFilterPB, FieldType}; use crate::services::cell::{CellDataChangeset, CellDataDecoder}; @@ -198,7 +199,52 @@ impl DateTypeOption { } } -impl TypeOptionTransform for DateTypeOption {} +#[async_trait] +impl TypeOptionTransform for DateTypeOption { + async fn transform_type_option( + &mut self, + view_id: &str, + field_id: &str, + old_type_option_field_type: FieldType, + _old_type_option_data: TypeOptionData, + _new_type_option_field_type: FieldType, + database: &mut Database, + ) { + match old_type_option_field_type { + FieldType::RichText => { + let rows = database + .get_cells_for_field(view_id, field_id) + .await + .into_iter() + .filter_map(|row| row.cell.map(|cell| (row.row_id, cell))) + .collect::>(); + + info!( + "Transforming RichText to DateTypeOption, updating {} row's cell content", + rows.len() + ); + for (row_id, cell_data) in rows { + if let Some(cell_data) = cell_data + .get_as::(CELL_DATA) + .and_then(|s| cast_string_to_timestamp(&s)) + .map(DateCellData::from_timestamp) + { + database + .update_row(row_id, |row| { + row.update_cells(|cell| { + cell.insert(field_id, Cell::from(&cell_data)); + }); + }) + .await; + } + } + }, + _ => { + // do nothing + }, + } + } +} impl CellDataDecoder for DateTypeOption { fn decode_cell(&self, cell: &Cell) -> FlowyResult<::CellData> { diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs index 5961926f02..a9fca50283 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/number_type_option/number_type_option.rs @@ -1,18 +1,19 @@ +use async_trait::async_trait; use collab::preclude::encoding::serde::from_any; use collab::preclude::Any; use collab::util::AnyMapExt; -use std::cmp::Ordering; -use std::default::Default; -use std::str::FromStr; - +use collab_database::database::Database; use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder}; use collab_database::rows::{new_cell_builder, Cell}; use fancy_regex::Regex; +use flowy_error::FlowyResult; use lazy_static::lazy_static; use rust_decimal::Decimal; use serde::{Deserialize, Deserializer, Serialize}; - -use flowy_error::FlowyResult; +use std::cmp::Ordering; +use std::default::Default; +use std::str::FromStr; +use tracing::info; use crate::entities::{FieldType, NumberFilterPB}; use crate::services::cell::{CellDataChangeset, CellDataDecoder}; @@ -180,7 +181,51 @@ impl NumberTypeOption { } } -impl TypeOptionTransform for NumberTypeOption {} +#[async_trait] +impl TypeOptionTransform for NumberTypeOption { + async fn transform_type_option( + &mut self, + view_id: &str, + field_id: &str, + old_type_option_field_type: FieldType, + _old_type_option_data: TypeOptionData, + _new_type_option_field_type: FieldType, + database: &mut Database, + ) { + match old_type_option_field_type { + FieldType::RichText => { + let rows = database + .get_cells_for_field(view_id, field_id) + .await + .into_iter() + .filter_map(|row| row.cell.map(|cell| (row.row_id, cell))) + .collect::>(); + + info!( + "Transforming RichText to NumberTypeOption, updating {} row's cell content", + rows.len() + ); + for (row_id, cell_data) in rows { + if let Ok(num_cell) = self + .parse_cell(&cell_data) + .and_then(|num_cell_data| self.format_cell_data(num_cell_data)) + { + database + .update_row(row_id, |row| { + row.update_cells(|cell| { + cell.insert(field_id, NumberCellData::from(num_cell.to_string())); + }); + }) + .await; + } + } + }, + _ => { + // do nothing + }, + } + } +} impl CellDataDecoder for NumberTypeOption { fn decode_cell(&self, cell: &Cell) -> FlowyResult<::CellData> { diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs index a366127a51..b464f9cd04 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/select_type_option.rs @@ -80,7 +80,8 @@ where field_id: &str, old_type_option_field_type: FieldType, old_type_option_data: TypeOptionData, - database: &Database, + new_type_option_field_type: FieldType, + database: &mut Database, ) { SelectOptionTypeOptionTransformHelper::transform_type_option( self, @@ -88,6 +89,7 @@ where field_id, &old_type_option_field_type, old_type_option_data, + new_type_option_field_type, database, ) .await; diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/type_option_transform.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/type_option_transform.rs index 25dfcfd7cc..048f5536ae 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/type_option_transform.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/selection_type_option/type_option_transform.rs @@ -8,6 +8,7 @@ use collab_database::database::Database; use collab_database::entity::{SelectOption, SelectOptionColor}; use collab_database::fields::TypeOptionData; use collab_database::template::option_parse::build_options_from_cells; +use tracing::info; /// Handles how to transform the cell data when switching between different field types pub(crate) struct SelectOptionTypeOptionTransformHelper(); @@ -24,7 +25,8 @@ impl SelectOptionTypeOptionTransformHelper { field_id: &str, old_field_type: &FieldType, old_type_option_data: TypeOptionData, - database: &Database, + new_field_type: FieldType, + database: &mut Database, ) where T: SelectTypeOptionSharedAction + TypeOption, { @@ -34,19 +36,44 @@ impl SelectOptionTypeOptionTransformHelper { return; } let text_type_option = RichTextTypeOption::from(old_type_option_data); - let cells = database + let rows = database .get_cells_for_field(view_id, field_id) .await .into_iter() - .filter_map(|e| e.cell) - .map(|cell| { - text_type_option + .filter_map(|row| row.cell.map(|cell| (row.row_id, cell))) + .map(|(row_id, cell)| { + let text = text_type_option .decode_cell(&cell) .unwrap_or_default() - .into_inner() + .into_inner(); + (row_id, text) }) .collect::>(); - let options = build_options_from_cells(&cells); + + let options = + build_options_from_cells(&rows.iter().map(|row| row.1.clone()).collect::>()); + info!( + "Transforming RichText to SelectOption, updating {} row's cell content", + rows.len() + ); + for (row_id, text_cell) in rows { + let mut transformed_ids = Vec::new(); + if let Some(option) = options.iter().find(|option| option.name == text_cell) { + transformed_ids.push(option.id.clone()); + } + + database + .update_row(row_id, |row| { + row.update_cells(|cell| { + cell.insert( + field_id, + SelectOptionIds::from(transformed_ids).to_cell_data(new_field_type), + ); + }); + }) + .await; + } + shared.mut_options().extend(options); }, FieldType::Checkbox => { diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs index 02844905db..7563e753c5 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/type_option.rs @@ -112,7 +112,8 @@ pub trait TypeOptionTransform: TypeOption + Send + Sync { _field_id: &str, _old_type_option_field_type: FieldType, _old_type_option_data: TypeOptionData, - _database: &Database, + _new_type_option_field_type: FieldType, + _database: &mut Database, ) { } } diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs index 9c965b6b21..5184048f5d 100644 --- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs +++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/url_type_option/url_type_option.rs @@ -1,12 +1,6 @@ use collab::preclude::encoding::serde::from_any; use collab::preclude::Any; -use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder}; -use collab_database::rows::Cell; -use flowy_error::FlowyResult; -use serde::{Deserialize, Serialize}; -use std::cmp::Ordering; - use crate::entities::{FieldType, TextFilterPB, URLCellDataPB}; use crate::services::cell::{CellDataChangeset, CellDataDecoder}; use crate::services::field::{ @@ -14,6 +8,14 @@ use crate::services::field::{ TypeOptionTransform, URLCellData, }; use crate::services::sort::SortCondition; +use async_trait::async_trait; +use collab_database::database::Database; +use collab_database::fields::{Field, TypeOptionData, TypeOptionDataBuilder}; +use collab_database::rows::Cell; +use flowy_error::FlowyResult; +use serde::{Deserialize, Serialize}; +use std::cmp::Ordering; +use tracing::trace; #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct URLTypeOption { @@ -45,7 +47,46 @@ impl From for TypeOptionData { } } -impl TypeOptionTransform for URLTypeOption {} +#[async_trait] +impl TypeOptionTransform for URLTypeOption { + async fn transform_type_option( + &mut self, + view_id: &str, + field_id: &str, + old_type_option_field_type: FieldType, + _old_type_option_data: TypeOptionData, + _new_type_option_field_type: FieldType, + database: &mut Database, + ) { + match old_type_option_field_type { + FieldType::RichText => { + let rows = database + .get_cells_for_field(view_id, field_id) + .await + .into_iter() + .filter_map(|row| row.cell.map(|cell| (row.row_id, cell))) + .collect::>(); + + trace!( + "Transforming RichText to URLTypeOption, updating {} row's cell content", + rows.len() + ); + for (row_id, cell_data) in rows { + database + .update_row(row_id, |row| { + row.update_cells(|cell| { + cell.insert(field_id, Self::CellData::from(&cell_data)); + }); + }) + .await; + } + }, + _ => { + // Do nothing + }, + } + } +} impl TypeOptionCellDataSerde for URLTypeOption { fn protobuf_encode( diff --git a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs index 7c6f4c316e..b9c61ca1fa 100644 --- a/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/filter/controller.rs @@ -109,6 +109,10 @@ impl FilterController { } } + pub async fn has_filters(&self) -> bool { + !self.filters.read().await.is_empty() + } + pub async fn close(&self) { if let Ok(mut task_scheduler) = self.task_scheduler.try_write() { task_scheduler.unregister_handler(&self.handler_id).await; diff --git a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs index b8d490e2a6..782ba06d9e 100644 --- a/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs +++ b/frontend/rust-lib/flowy-database2/src/services/sort/controller.rs @@ -84,6 +84,10 @@ impl SortController { } } + pub async fn has_sorts(&self) -> bool { + !self.sorts.is_empty() + } + pub async fn did_receive_row_changed(&self, row_id: RowId) { if !self.sorts.is_empty() { self