From aeb29d2e4226c136488b7c783aa0afbfbb20447e Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:10:57 +0800 Subject: [PATCH] ci: fix potential test fail (#1722) --- .../cell/select_option_editor_bloc.dart | 75 +++++++++---------- .../widgets/cell/number_cell.dart | 13 +--- .../flowy-revision/src/rev_manager.rs | 2 +- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/frontend/app_flowy/lib/plugins/grid/application/cell/select_option_editor_bloc.dart b/frontend/app_flowy/lib/plugins/grid/application/cell/select_option_editor_bloc.dart index 62b6f48423..de00ab3387 100644 --- a/frontend/app_flowy/lib/plugins/grid/application/cell/select_option_editor_bloc.dart +++ b/frontend/app_flowy/lib/plugins/grid/application/cell/select_option_editor_bloc.dart @@ -13,7 +13,6 @@ class SelectOptionCellEditorBloc extends Bloc { final SelectOptionFFIService _selectOptionService; final GridSelectOptionCellController cellController; - Timer? _delayOperation; SelectOptionCellEditorBloc({ required this.cellController, @@ -25,7 +24,7 @@ class SelectOptionCellEditorBloc await event.map( initial: (_Initial value) async { _startListening(); - _loadOptions(); + await _loadOptions(); }, didReceiveOptions: (_DidReceiveOptions value) { final result = _makeOptions(state.filter, value.options); @@ -36,28 +35,28 @@ class SelectOptionCellEditorBloc selectedOptions: value.selectedOptions, )); }, - newOption: (_NewOption value) { - _createOption(value.optionName); + newOption: (_NewOption value) async { + await _createOption(value.optionName); emit(state.copyWith( filter: none(), )); }, - deleteOption: (_DeleteOption value) { - _deleteOption([value.option]); + deleteOption: (_DeleteOption value) async { + await _deleteOption([value.option]); }, - deleteAllOptions: (_DeleteAllOptions value) { + deleteAllOptions: (_DeleteAllOptions value) async { if (state.allOptions.isNotEmpty) { - _deleteOption(state.allOptions); + await _deleteOption(state.allOptions); } }, - updateOption: (_UpdateOption value) { - _updateOption(value.option); + updateOption: (_UpdateOption value) async { + await _updateOption(value.option); }, - selectOption: (_SelectOption value) { - _selectOptionService.select(optionIds: [value.optionId]); + selectOption: (_SelectOption value) async { + await _selectOptionService.select(optionIds: [value.optionId]); }, - unSelectOption: (_UnSelectOption value) { - _selectOptionService.unSelect(optionIds: [value.optionId]); + unSelectOption: (_UnSelectOption value) async { + await _selectOptionService.unSelect(optionIds: [value.optionId]); }, trySelectOption: (_TrySelectOption value) { _trySelectOption(value.optionName, emit); @@ -78,22 +77,21 @@ class SelectOptionCellEditorBloc @override Future close() async { - _delayOperation?.cancel(); await cellController.dispose(); return super.close(); } - void _createOption(String name) async { + Future _createOption(String name) async { final result = await _selectOptionService.create(name: name); result.fold((l) => {}, (err) => Log.error(err)); } - void _deleteOption(List options) async { + Future _deleteOption(List options) async { final result = await _selectOptionService.delete(options: options); result.fold((l) => null, (err) => Log.error(err)); } - void _updateOption(SelectOptionPB option) async { + Future _updateOption(SelectOptionPB option) async { final result = await _selectOptionService.update( option: option, ); @@ -158,25 +156,24 @@ class SelectOptionCellEditorBloc )); } - void _loadOptions() { - _delayOperation?.cancel(); - _delayOperation = Timer(const Duration(milliseconds: 10), () { - _selectOptionService.getOptionContext().then((result) { - if (isClosed) { - return; - } - return result.fold( - (data) => add( - SelectOptionEditorEvent.didReceiveOptions( - data.options, data.selectOptions), - ), - (err) { - Log.error(err); - return null; - }, - ); - }); - }); + Future _loadOptions() async { + final result = await _selectOptionService.getOptionContext(); + if (isClosed) { + return; + } + + return result.fold( + (data) => add( + SelectOptionEditorEvent.didReceiveOptions( + data.options, + data.selectOptions, + ), + ), + (err) { + Log.error(err); + return null; + }, + ); } _MakeOptionResult _makeOptions( @@ -210,9 +207,7 @@ class SelectOptionCellEditorBloc void _startListening() { cellController.startListening( onCellChanged: ((selectOptionContext) { - if (!isClosed) { - _loadOptions(); - } + _loadOptions(); }), onCellFieldChanged: () { _loadOptions(); diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/number_cell.dart index c7141a43b3..53badd13b0 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/number_cell.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/number_cell.dart @@ -22,7 +22,6 @@ class GridNumberCell extends GridCellWidget { class _NumberCellState extends GridFocusNodeCellState { late NumberCellBloc _cellBloc; late TextEditingController _controller; - Timer? _delayOperation; @override void initState() { @@ -67,7 +66,6 @@ class _NumberCellState extends GridFocusNodeCellState { @override Future dispose() async { - _delayOperation = null; _cellBloc.close(); super.dispose(); } @@ -75,13 +73,10 @@ class _NumberCellState extends GridFocusNodeCellState { @override Future focusChanged() async { if (mounted) { - _delayOperation?.cancel(); - _delayOperation = Timer(const Duration(milliseconds: 30), () { - if (_cellBloc.isClosed == false && - _controller.text != _cellBloc.state.cellContent) { - _cellBloc.add(NumberCellEvent.updateCell(_controller.text)); - } - }); + if (_cellBloc.isClosed == false && + _controller.text != _cellBloc.state.cellContent) { + _cellBloc.add(NumberCellEvent.updateCell(_controller.text)); + } } } diff --git a/frontend/rust-lib/flowy-revision/src/rev_manager.rs b/frontend/rust-lib/flowy-revision/src/rev_manager.rs index 9e5e145857..23cc994ca3 100644 --- a/frontend/rust-lib/flowy-revision/src/rev_manager.rs +++ b/frontend/rust-lib/flowy-revision/src/rev_manager.rs @@ -127,7 +127,7 @@ impl RevisionManager { } } - #[tracing::instrument(name = "revision_manager_initialize", level = "info", skip_all, fields(deserializer, object_id, deserialize_revisions) err)] + #[tracing::instrument(name = "revision_manager_initialize", level = "debug", skip_all, fields(deserializer, object_id, deserialize_revisions) err)] pub async fn initialize(&mut self, _cloud: Option>) -> FlowyResult where B: RevisionObjectDeserializer,