chore: fix database filter (#6094)

* chore: fix database filter

* chore: fix test
This commit is contained in:
Nathan.fooo 2024-08-28 16:15:40 +08:00 committed by GitHub
parent 956d62fe82
commit 9a295daf99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 169 additions and 121 deletions

View File

@ -55,6 +55,8 @@ class RowCache {
final RowLifeCycle _rowLifeCycle; final RowLifeCycle _rowLifeCycle;
final RowFieldsDelegate _fieldDelegate; final RowFieldsDelegate _fieldDelegate;
RowChangesetNotifier? _changedNotifier; RowChangesetNotifier? _changedNotifier;
bool _isInitialRows = false;
final List<RowsVisibilityChangePB> _pendingVisibilityChanges = [];
/// Returns a unmodifiable list of RowInfo /// Returns a unmodifiable list of RowInfo
UnmodifiableListView<RowInfo> get rowInfos { UnmodifiableListView<RowInfo> get rowInfos {
@ -80,7 +82,13 @@ class RowCache {
final rowInfo = buildGridRow(row); final rowInfo = buildGridRow(row);
_rowList.add(rowInfo); _rowList.add(rowInfo);
} }
_isInitialRows = true;
_changedNotifier?.receive(const ChangedReason.setInitialRows()); _changedNotifier?.receive(const ChangedReason.setInitialRows());
for (final changeset in _pendingVisibilityChanges) {
applyRowsVisibility(changeset);
}
_pendingVisibilityChanges.clear();
} }
void setRowMeta(RowMetaPB rowMeta) { void setRowMeta(RowMetaPB rowMeta) {
@ -103,8 +111,12 @@ class RowCache {
} }
void applyRowsVisibility(RowsVisibilityChangePB changeset) { void applyRowsVisibility(RowsVisibilityChangePB changeset) {
if (_isInitialRows) {
_hideRows(changeset.invisibleRows); _hideRows(changeset.invisibleRows);
_showRows(changeset.visibleRows); _showRows(changeset.visibleRows);
} else {
_pendingVisibilityChanges.add(changeset);
}
} }
void reorderAllRows(List<String> rowIds) { void reorderAllRows(List<String> rowIds) {

View File

@ -202,11 +202,18 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
); );
}, },
endEditingHeader: (String groupId, String? groupName) async { endEditingHeader: (String groupId, String? groupName) async {
final group = groupControllers[groupId]?.group;
if (group != null) {
if (generateGroupNameFromGroup(group) != groupName) {
await groupBackendSvc.updateGroup( await groupBackendSvc.updateGroup(
fieldId: groupControllers.values.first.group.fieldId, fieldId: groupControllers.values.first.group.fieldId,
groupId: groupId, groupId: groupId,
name: groupName, name: groupName,
); );
return;
}
}
state.maybeMap( state.maybeMap(
ready: (state) => emit(state.copyWith(editingHeaderId: null)), ready: (state) => emit(state.copyWith(editingHeaderId: null)),
orElse: () {}, orElse: () {},

View File

@ -556,10 +556,8 @@ class _BoardCardState extends State<_BoardCard> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final boardBloc = context.read<BoardBloc>(); final boardBloc = context.read<BoardBloc>();
final groupData = widget.afGroupData.customData as GroupData; final groupData = widget.afGroupData.customData as GroupData;
final rowCache = boardBloc.rowCache; final rowCache = boardBloc.rowCache;
final databaseController = boardBloc.databaseController; final databaseController = boardBloc.databaseController;
final rowMeta = final rowMeta =
rowCache.getRow(widget.groupItem.id)?.rowMeta ?? widget.groupItem.row; rowCache.getRow(widget.groupItem.id)?.rowMeta ?? widget.groupItem.row;

View File

@ -172,7 +172,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]] [[package]]
name = "app-error" name = "app-error"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -192,7 +192,7 @@ dependencies = [
[[package]] [[package]]
name = "appflowy-ai-client" name = "appflowy-ai-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -837,7 +837,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api" name = "client-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"again", "again",
"anyhow", "anyhow",
@ -888,7 +888,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api-entity" name = "client-api-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"collab-entity", "collab-entity",
"collab-rt-entity", "collab-rt-entity",
@ -901,7 +901,7 @@ dependencies = [
[[package]] [[package]]
name = "client-websocket" name = "client-websocket"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
@ -1149,7 +1149,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-entity" name = "collab-rt-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -1174,7 +1174,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-protocol" name = "collab-rt-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1571,7 +1571,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]] [[package]]
name = "database-entity" name = "database-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3117,7 +3117,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue" name = "gotrue"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures-util", "futures-util",
@ -3134,7 +3134,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue-entity" name = "gotrue-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3566,7 +3566,7 @@ dependencies = [
[[package]] [[package]]
name = "infra" name = "infra"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -6169,7 +6169,7 @@ dependencies = [
[[package]] [[package]]
name = "shared-entity" name = "shared-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",

View File

@ -53,7 +53,7 @@ collab-user = { version = "0.2" }
# Run the script: # Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id # scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️ # ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5badffc97b17984d5f25a178c0c5a477338039c4" } client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "cccdf76116f41631daa5533b56238aec323684de" }
[dependencies] [dependencies]
serde_json.workspace = true serde_json.workspace = true

View File

@ -163,7 +163,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]] [[package]]
name = "app-error" name = "app-error"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -183,7 +183,7 @@ dependencies = [
[[package]] [[package]]
name = "appflowy-ai-client" name = "appflowy-ai-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -811,7 +811,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api" name = "client-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"again", "again",
"anyhow", "anyhow",
@ -862,7 +862,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api-entity" name = "client-api-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"collab-entity", "collab-entity",
"collab-rt-entity", "collab-rt-entity",
@ -875,7 +875,7 @@ dependencies = [
[[package]] [[package]]
name = "client-websocket" name = "client-websocket"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
@ -1132,7 +1132,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-entity" name = "collab-rt-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -1157,7 +1157,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-protocol" name = "collab-rt-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1561,7 +1561,7 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
[[package]] [[package]]
name = "database-entity" name = "database-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3184,7 +3184,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue" name = "gotrue"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures-util", "futures-util",
@ -3201,7 +3201,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue-entity" name = "gotrue-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3638,7 +3638,7 @@ dependencies = [
[[package]] [[package]]
name = "infra" name = "infra"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -6233,7 +6233,7 @@ dependencies = [
[[package]] [[package]]
name = "shared-entity" name = "shared-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",

View File

@ -52,7 +52,7 @@ collab-user = { version = "0.2" }
# Run the script: # Run the script:
# scripts/tool/update_client_api_rev.sh new_rev_id # scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️ # ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5badffc97b17984d5f25a178c0c5a477338039c4" } client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "cccdf76116f41631daa5533b56238aec323684de" }
[dependencies] [dependencies]
serde_json.workspace = true serde_json.workspace = true

View File

@ -163,7 +163,7 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]] [[package]]
name = "app-error" name = "app-error"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -183,7 +183,7 @@ dependencies = [
[[package]] [[package]]
name = "appflowy-ai-client" name = "appflowy-ai-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -729,7 +729,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api" name = "client-api"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"again", "again",
"anyhow", "anyhow",
@ -780,7 +780,7 @@ dependencies = [
[[package]] [[package]]
name = "client-api-entity" name = "client-api-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"collab-entity", "collab-entity",
"collab-rt-entity", "collab-rt-entity",
@ -793,7 +793,7 @@ dependencies = [
[[package]] [[package]]
name = "client-websocket" name = "client-websocket"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"futures-channel", "futures-channel",
"futures-util", "futures-util",
@ -1010,7 +1010,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-entity" name = "collab-rt-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bincode", "bincode",
@ -1035,7 +1035,7 @@ dependencies = [
[[package]] [[package]]
name = "collab-rt-protocol" name = "collab-rt-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@ -1395,7 +1395,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]] [[package]]
name = "database-entity" name = "database-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -2795,7 +2795,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue" name = "gotrue"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"futures-util", "futures-util",
@ -2812,7 +2812,7 @@ dependencies = [
[[package]] [[package]]
name = "gotrue-entity" name = "gotrue-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",
@ -3177,7 +3177,7 @@ dependencies = [
[[package]] [[package]]
name = "infra" name = "infra"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -5377,7 +5377,7 @@ dependencies = [
[[package]] [[package]]
name = "shared-entity" name = "shared-entity"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5badffc97b17984d5f25a178c0c5a477338039c4#5badffc97b17984d5f25a178c0c5a477338039c4" source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=cccdf76116f41631daa5533b56238aec323684de#cccdf76116f41631daa5533b56238aec323684de"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app-error", "app-error",

View File

@ -100,8 +100,8 @@ dashmap = "6.0.1"
# Run the script.add_workspace_members: # Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id # scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️ # ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5badffc97b17984d5f25a178c0c5a477338039c4" } client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "cccdf76116f41631daa5533b56238aec323684de" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5badffc97b17984d5f25a178c0c5a477338039c4" } client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "cccdf76116f41631daa5533b56238aec323684de" }
[profile.dev] [profile.dev]
opt-level = 0 opt-level = 0

View File

@ -38,6 +38,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
cloud_config: &Option<UserCloudConfig>, cloud_config: &Option<UserCloudConfig>,
user_workspace: &UserWorkspace, user_workspace: &UserWorkspace,
_device_id: &str, _device_id: &str,
authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
self self
.server_provider .server_provider
@ -64,7 +65,10 @@ impl UserStatusCallback for UserStatusCallbackImpl {
}, },
) )
.await?; .await?;
self.database_manager.initialize(user_id).await?; self
.database_manager
.initialize(user_id, authenticator == &Authenticator::Local)
.await?;
self.document_manager.initialize(user_id).await?; self.document_manager.initialize(user_id).await?;
Ok(()) Ok(())
} }
@ -74,6 +78,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
user_id: i64, user_id: i64,
user_workspace: &UserWorkspace, user_workspace: &UserWorkspace,
device_id: &str, device_id: &str,
authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
event!( event!(
tracing::Level::TRACE, tracing::Level::TRACE,
@ -86,7 +91,10 @@ impl UserStatusCallback for UserStatusCallbackImpl {
.folder_manager .folder_manager
.initialize_with_workspace_id(user_id) .initialize_with_workspace_id(user_id)
.await?; .await?;
self.database_manager.initialize(user_id).await?; self
.database_manager
.initialize(user_id, authenticator.is_local())
.await?;
self.document_manager.initialize(user_id).await?; self.document_manager.initialize(user_id).await?;
Ok(()) Ok(())
} }
@ -97,6 +105,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
user_profile: &UserProfile, user_profile: &UserProfile,
user_workspace: &UserWorkspace, user_workspace: &UserWorkspace,
device_id: &str, device_id: &str,
authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
self self
.server_provider .server_provider
@ -156,7 +165,7 @@ impl UserStatusCallback for UserStatusCallbackImpl {
self self
.database_manager .database_manager
.initialize_with_new_user(user_profile.uid) .initialize_with_new_user(user_profile.uid, authenticator.is_local())
.await .await
.context("DatabaseManager error")?; .context("DatabaseManager error")?;
@ -173,12 +182,20 @@ impl UserStatusCallback for UserStatusCallbackImpl {
Ok(()) Ok(())
} }
async fn open_workspace(&self, user_id: i64, user_workspace: &UserWorkspace) -> FlowyResult<()> { async fn open_workspace(
&self,
user_id: i64,
user_workspace: &UserWorkspace,
authenticator: &Authenticator,
) -> FlowyResult<()> {
self self
.folder_manager .folder_manager
.initialize_with_workspace_id(user_id) .initialize_with_workspace_id(user_id)
.await?; .await?;
self.database_manager.initialize(user_id).await?; self
.database_manager
.initialize(user_id, authenticator.is_local())
.await?;
self.document_manager.initialize(user_id).await?; self.document_manager.initialize(user_id).await?;
self.ai_manager.initialize(&user_workspace.id).await?; self.ai_manager.initialize(&user_workspace.id).await?;
self.storage_manager.initialize(&user_workspace.id).await; self.storage_manager.initialize(&user_workspace.id).await;

View File

@ -82,7 +82,7 @@ impl DatabaseManager {
} }
/// When initialize with new workspace, all the resources will be cleared. /// When initialize with new workspace, all the resources will be cleared.
pub async fn initialize(&self, uid: i64) -> FlowyResult<()> { pub async fn initialize(&self, uid: i64, is_local_user: bool) -> FlowyResult<()> {
// 1. Clear all existing tasks // 1. Clear all existing tasks
self.task_scheduler.write().await.clear_task(); self.task_scheduler.write().await.clear_task();
// 2. Release all existing editors // 2. Release all existing editors
@ -99,6 +99,7 @@ impl DatabaseManager {
let collab_db = self.user.collab_db(uid)?; let collab_db = self.user.collab_db(uid)?;
let collab_service = WorkspaceDatabaseCollabServiceImpl::new( let collab_service = WorkspaceDatabaseCollabServiceImpl::new(
is_local_user,
self.user.clone(), self.user.clone(),
self.collab_builder.clone(), self.collab_builder.clone(),
self.cloud_service.clone(), self.cloud_service.clone(),
@ -168,8 +169,12 @@ impl DatabaseManager {
skip_all, skip_all,
err err
)] )]
pub async fn initialize_with_new_user(&self, user_id: i64) -> FlowyResult<()> { pub async fn initialize_with_new_user(
self.initialize(user_id).await?; &self,
user_id: i64,
is_local_user: bool,
) -> FlowyResult<()> {
self.initialize(user_id, is_local_user).await?;
Ok(()) Ok(())
} }
@ -630,6 +635,7 @@ impl DatabaseManager {
} }
struct WorkspaceDatabaseCollabServiceImpl { struct WorkspaceDatabaseCollabServiceImpl {
is_local_user: bool,
user: Arc<dyn DatabaseUser>, user: Arc<dyn DatabaseUser>,
collab_builder: Arc<AppFlowyCollabBuilder>, collab_builder: Arc<AppFlowyCollabBuilder>,
persistence: Arc<dyn DatabaseCollabPersistenceService>, persistence: Arc<dyn DatabaseCollabPersistenceService>,
@ -639,12 +645,14 @@ struct WorkspaceDatabaseCollabServiceImpl {
impl WorkspaceDatabaseCollabServiceImpl { impl WorkspaceDatabaseCollabServiceImpl {
fn new( fn new(
is_local_user: bool,
user: Arc<dyn DatabaseUser>, user: Arc<dyn DatabaseUser>,
collab_builder: Arc<AppFlowyCollabBuilder>, collab_builder: Arc<AppFlowyCollabBuilder>,
cloud_service: Arc<dyn DatabaseCloudService>, cloud_service: Arc<dyn DatabaseCloudService>,
) -> Self { ) -> Self {
let persistence = DatabasePersistenceImpl { user: user.clone() }; let persistence = DatabasePersistenceImpl { user: user.clone() };
Self { Self {
is_local_user,
user, user,
collab_builder, collab_builder,
persistence: Arc::new(persistence), persistence: Arc::new(persistence),
@ -783,15 +791,18 @@ impl DatabaseCollabService for WorkspaceDatabaseCollabServiceImpl {
DataSource::from(encode_collab) DataSource::from(encode_collab)
}, },
Ok(None) => { Ok(None) => {
info!( if self.is_local_user {
"build collab: {}:{} with empty encode collab",
collab_type, object_id
);
// when collab not exist, create a default collab
CollabPersistenceImpl { CollabPersistenceImpl {
persistence: Some(self.persistence.clone()), persistence: Some(self.persistence.clone()),
} }
.into() .into()
} else {
error!(
"build collab: {}:{} with empty encode collab",
collab_type, object_id
);
return Err(DatabaseError::RecordNotFound);
}
}, },
Err(err) => { Err(err) => {
error!("build collab: failed to get encode collab: {}", err); error!("build collab: failed to get encode collab: {}", err);

View File

@ -5,7 +5,7 @@ use crate::services::cell::{apply_cell_changeset, get_cell_protobuf, CellCache};
use crate::services::database::database_observe::*; use crate::services::database::database_observe::*;
use crate::services::database::util::database_view_setting_pb_from_view; use crate::services::database::util::database_view_setting_pb_from_view;
use crate::services::database_view::{ use crate::services::database_view::{
DatabaseViewChanged, DatabaseViewOperation, DatabaseViews, EditorByViewId, DatabaseViewChanged, DatabaseViewEditor, DatabaseViewOperation, DatabaseViews, EditorByViewId,
}; };
use crate::services::field::type_option_transform::transform_type_option; use crate::services::field::type_option_transform::transform_type_option;
use crate::services::field::{ use crate::services::field::{
@ -1355,57 +1355,7 @@ impl DatabaseEditor {
} }
let row_orders = self.database.read().await.get_row_orders_for_view(view_id); let row_orders = self.database.read().await.get_row_orders_for_view(view_id);
let cloned_database = Arc::downgrade(&self.database);
let cloned_row_orders = row_orders.clone(); let cloned_row_orders = row_orders.clone();
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<DatabaseViews>| 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() {
None => break,
Some(database) => {
for row_order in chunk_row_orders {
if let Some(database_row) =
database.read().await.init_database_row(&row_order.id).await
{
if let Some(row) = database_row.read().await.get_row() {
loaded_rows.push(Arc::new(row));
}
}
}
// stop init database rows
if new_token.is_cancelled() {
return;
}
if loaded_rows.len() % 1000 == 0 {
apply_filter_and_sort(loaded_rows.clone(), opening_database_views.clone()).await;
}
},
}
tokio::task::yield_now().await;
}
apply_filter_and_sort(loaded_rows.clone(), opening_database_views).await;
});
// Collect database details in a single block holding the `read` lock // Collect database details in a single block holding the `read` lock
let (database_id, fields, is_linked) = { let (database_id, fields, is_linked) = {
let database = self.database.read().await; let database = self.database.read().await;
@ -1431,6 +1381,54 @@ impl DatabaseEditor {
fields.len(), fields.len(),
rows.len() rows.len()
); );
trace!("[Database]: start loading rows");
let cloned_database = Arc::downgrade(&self.database);
let view_editor = self.database_views.get_view_editor(view_id).await?;
tokio::spawn(async move {
const CHUNK_SIZE: usize = 10;
let apply_filter_and_sort =
|mut loaded_rows: Vec<Arc<Row>>, view_editor: Arc<DatabaseViewEditor>| async move {
if view_editor.has_filters().await {
trace!("[Database]: filtering rows:{}", loaded_rows.len());
view_editor.v_filter_rows_and_notify(&mut loaded_rows).await;
}
if view_editor.has_sorts().await {
trace!("[Database]: sorting rows:{}", loaded_rows.len());
view_editor.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() {
None => break,
Some(database) => {
for row_order in chunk_row_orders {
if let Some(database_row) =
database.read().await.init_database_row(&row_order.id).await
{
if let Some(row) = database_row.read().await.get_row() {
loaded_rows.push(Arc::new(row));
}
}
}
// stop init database rows
if new_token.is_cancelled() {
info!("[Database]: stop loading database rows");
return;
}
},
}
tokio::task::yield_now().await;
}
info!("[Database]: Finish loading rows: {}", loaded_rows.len());
apply_filter_and_sort(loaded_rows.clone(), view_editor).await;
});
Ok::<_, FlowyError>(DatabasePB { Ok::<_, FlowyError>(DatabasePB {
id: database_id, id: database_id,
fields, fields,

View File

@ -11,7 +11,7 @@ use flowy_error::FlowyResult;
use lib_infra::priority_task::{QualityOfService, Task, TaskContent, TaskDispatcher}; use lib_infra::priority_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tracing::error; use tracing::{error, trace};
use crate::entities::filter_entities::*; use crate::entities::filter_entities::*;
use crate::entities::{FieldType, InsertedRowPB, RowMetaPB}; use crate::entities::{FieldType, InsertedRowPB, RowMetaPB};
@ -74,14 +74,13 @@ impl FilterController {
let mut need_save = false; let mut need_save = false;
let mut filters = delegate.get_all_filters(view_id).await; let mut filters = delegate.get_all_filters(view_id).await;
trace!("[Database]: filters: {:?}", filters);
let mut filtering_field_ids: HashMap<String, Vec<String>> = HashMap::new(); let mut filtering_field_ids: HashMap<String, Vec<String>> = HashMap::new();
for filter in filters.iter() { for filter in filters.iter() {
filter.get_all_filtering_field_ids(&mut filtering_field_ids); filter.get_all_filtering_field_ids(&mut filtering_field_ids);
} }
let mut delete_filter_ids = vec![]; let mut delete_filter_ids = vec![];
for (field_id, filter_ids) in &filtering_field_ids { for (field_id, filter_ids) in &filtering_field_ids {
if !field_ids.contains(field_id) { if !field_ids.contains(field_id) {
need_save = true; need_save = true;
@ -385,7 +384,6 @@ impl FilterController {
invisible_rows, invisible_rows,
visible_rows, visible_rows,
}; };
tracing::trace!("filter result {:?}", notification);
let _ = self let _ = self
.notifier .notifier
.send(DatabaseViewChanged::FilterNotification(notification)); .send(DatabaseViewChanged::FilterNotification(notification));

View File

@ -290,6 +290,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
_cloud_config: &Option<UserCloudConfig>, _cloud_config: &Option<UserCloudConfig>,
_user_workspace: &UserWorkspace, _user_workspace: &UserWorkspace,
_device_id: &str, _device_id: &str,
_authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
Ok(()) Ok(())
} }
@ -299,6 +300,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
_user_id: i64, _user_id: i64,
_user_workspace: &UserWorkspace, _user_workspace: &UserWorkspace,
_device_id: &str, _device_id: &str,
_authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
Ok(()) Ok(())
} }
@ -309,6 +311,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
_user_profile: &UserProfile, _user_profile: &UserProfile,
_user_workspace: &UserWorkspace, _user_workspace: &UserWorkspace,
_device_id: &str, _device_id: &str,
_authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
Ok(()) Ok(())
} }
@ -320,6 +323,7 @@ pub trait UserStatusCallback: Send + Sync + 'static {
&self, &self,
_user_id: i64, _user_id: i64,
_user_workspace: &UserWorkspace, _user_workspace: &UserWorkspace,
_authenticator: &Authenticator,
) -> FlowyResult<()> { ) -> FlowyResult<()> {
Ok(()) Ok(())
} }

View File

@ -280,6 +280,7 @@ impl UserManager {
&cloud_config, &cloud_config,
&session.user_workspace, &session.user_workspace,
&self.authenticate_user.user_config.device_id, &self.authenticate_user.user_config.device_id,
&user.authenticator,
) )
.await?; .await?;
} }
@ -352,6 +353,7 @@ impl UserManager {
user_profile.uid, user_profile.uid,
&latest_workspace, &latest_workspace,
&self.authenticate_user.user_config.device_id, &self.authenticate_user.user_config.device_id,
&authenticator,
) )
.await?; .await?;
send_auth_state_notification(AuthStateChangedPB { send_auth_state_notification(AuthStateChangedPB {
@ -443,6 +445,7 @@ impl UserManager {
new_user_profile, new_user_profile,
&new_session.user_workspace, &new_session.user_workspace,
&self.authenticate_user.user_config.device_id, &self.authenticate_user.user_config.device_id,
authenticator,
) )
.await?; .await?;

View File

@ -196,7 +196,7 @@ impl UserManager {
.user_status_callback .user_status_callback
.read() .read()
.await .await
.open_workspace(uid, &user_workspace) .open_workspace(uid, &user_workspace, &user_profile.authenticator)
.await .await
{ {
error!("Open workspace failed: {:?}", err); error!("Open workspace failed: {:?}", err);