From 17c9c9b556fd22bd42cdab29b390753e5de186bd Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 13 Aug 2024 13:52:02 +0800 Subject: [PATCH] chore: optimize recent section performance (#5948) * fix: duplicated call for setting recent view * chore: reduce recent update --- .../workspace/application/tabs/tabs_bloc.dart | 7 +------ .../view_title/view_title_bar_bloc.dart | 16 ++++++++-------- .../presentation/widgets/view_title_bar.dart | 7 +++++++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart index 36d64e6989..07f325f6c7 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/tabs/tabs_bloc.dart @@ -1,14 +1,12 @@ -import 'package:flutter/foundation.dart'; - import 'package:appflowy/plugins/util.dart'; import 'package:appflowy/startup/plugin/plugin.dart'; import 'package:appflowy/startup/startup.dart'; -import 'package:appflowy/workspace/application/recent/cached_recent_service.dart'; import 'package:appflowy/workspace/application/view/view_ext.dart'; import 'package:appflowy/workspace/presentation/home/home_stack.dart'; import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:bloc/bloc.dart'; +import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'tabs_bloc.freezed.dart'; @@ -92,8 +90,5 @@ class TabsBloc extends Bloc { view: view, ), ); - - // Update recent views - getIt().updateRecentViews([view.id], true); } } diff --git a/frontend/appflowy_flutter/lib/workspace/application/view_title/view_title_bar_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/view_title/view_title_bar_bloc.dart index 35f13d3de2..45f3eebaca 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/view_title/view_title_bar_bloc.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/view_title/view_title_bar_bloc.dart @@ -10,19 +10,19 @@ class ViewTitleBarBloc extends Bloc { ViewTitleBarBloc({ required this.view, }) : super(ViewTitleBarState.initial()) { + viewListener = ViewListener( + viewId: view.id, + )..start( + onViewChildViewsUpdated: (p0) { + add(const ViewTitleBarEvent.reload()); + }, + ); + on( (event, emit) async { await event.when( initial: () async { add(const ViewTitleBarEvent.reload()); - - viewListener = ViewListener( - viewId: view.id, - )..start( - onViewUpdated: (p0) { - add(const ViewTitleBarEvent.reload()); - }, - ); }, reload: () async { final List ancestors = diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart index 7be2a4b155..43b14d9d1a 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart @@ -143,6 +143,13 @@ class _ViewTitleState extends State<_ViewTitle> { create: (_) => ViewTitleBloc(view: widget.view)..add(const ViewTitleEvent.initial()), child: BlocConsumer( + listenWhen: (previous, current) { + if (previous.view == null || current.view == null) { + return false; + } + + return previous.view != current.view; + }, listener: (_, state) { _resetTextEditingController(state); widget.onUpdated();