Skip to content

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

chore: optimize cell cache

appflowy32a1bbb6b949
diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_listener.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_listener.dart
index 5da5fce86d..4805ad8b7a 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_listener.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_listener.dart
@@ -11,13 +11,15 @@ typedef UpdateFieldNotifiedValue = Either<Unit, FlowyError>;
class CellListener {
final String rowId;
final String fieldId;
- PublishNotifier<UpdateFieldNotifiedValue>? _updateCellNotifier = PublishNotifier();
+ PublishNotifier<UpdateFieldNotifiedValue>? _updateCellNotifier =
+ PublishNotifier();
GridNotificationListener? _listener;
CellListener({required this.rowId, required this.fieldId});
void start({required void Function(UpdateFieldNotifiedValue) onCellChanged}) {
_updateCellNotifier?.addPublishListener(onCellChanged);
- _listener = GridNotificationListener(objectId: "$rowId:$fieldId", handler: _handler);
+ _listener = GridNotificationListener(
+ objectId: "$rowId:$fieldId", handler: _handler);
}
void _handler(GridNotification ty, Either<Uint8List, FlowyError> result) {
diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_cache.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_cache.dart
index 1f14c7c54a..3d816b21d1 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_cache.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/cell_cache.dart
@@ -33,10 +33,17 @@ class GridCellCache {
required this.gridId,
});
- void remove(String fieldId) {
+ void removeCellWithFieldId(String fieldId) {
_cellDataByFieldId.remove(fieldId);
}
+ void remove(GridCellCacheKey key) {
+ var map = _cellDataByFieldId[key.fieldId];
+ if (map != null) {
+ map.remove(key.rowId);
+ }
+ }
+
void insert<T extends GridCell>(GridCellCacheKey key, T value) {
var map = _cellDataByFieldId[key.fieldId];
if (map == null) {
diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart
index 8ab486a48c..d716133d05 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/cell/cell_service/context_builder.dart
@@ -191,7 +191,7 @@ class IGridCellController<T, D> extends Equatable {
_cellListener?.start(onCellChanged: (result) {
result.fold(
(_) {
- _cellsCache.remove(fieldId);
+ _cellsCache.remove(_cacheKey);
_loadData();
},
(err) => Log.error(err),
diff --git a/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart b/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart
index 68c8b6f519..d6cd387e74 100644
--- a/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart
+++ b/frontend/app_flowy/lib/plugins/grid/application/row/row_cache.dart
@@ -52,7 +52,8 @@ class GridRowCache {
//
notifier.onRowFieldsChanged(() => _rowChangeReasonNotifier
.receive(const RowsChangedReason.fieldDidChange()));
- notifier.onRowFieldChanged((field) => _cellCache.remove(field.id));
+ notifier.onRowFieldChanged(
+ (field) => _cellCache.removeCellWithFieldId(field.id));
_rowInfos = block.rows.map((rowPB) => buildGridRow(rowPB)).toList();
}