chore: optimize recent section performance (#5948)

* fix: duplicated call for setting recent view

* chore: reduce recent update
This commit is contained in:
Lucas.Xu 2024-08-13 13:52:02 +08:00 committed by GitHub
parent 93f9a2cab1
commit 17c9c9b556
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 14 deletions

View File

@ -1,14 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:appflowy/plugins/util.dart'; import 'package:appflowy/plugins/util.dart';
import 'package:appflowy/startup/plugin/plugin.dart'; import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.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/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart'; import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart'; import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
part 'tabs_bloc.freezed.dart'; part 'tabs_bloc.freezed.dart';
@ -92,8 +90,5 @@ class TabsBloc extends Bloc<TabsEvent, TabsState> {
view: view, view: view,
), ),
); );
// Update recent views
getIt<CachedRecentService>().updateRecentViews([view.id], true);
} }
} }

View File

@ -10,19 +10,19 @@ class ViewTitleBarBloc extends Bloc<ViewTitleBarEvent, ViewTitleBarState> {
ViewTitleBarBloc({ ViewTitleBarBloc({
required this.view, required this.view,
}) : super(ViewTitleBarState.initial()) { }) : super(ViewTitleBarState.initial()) {
viewListener = ViewListener(
viewId: view.id,
)..start(
onViewChildViewsUpdated: (p0) {
add(const ViewTitleBarEvent.reload());
},
);
on<ViewTitleBarEvent>( on<ViewTitleBarEvent>(
(event, emit) async { (event, emit) async {
await event.when( await event.when(
initial: () async { initial: () async {
add(const ViewTitleBarEvent.reload()); add(const ViewTitleBarEvent.reload());
viewListener = ViewListener(
viewId: view.id,
)..start(
onViewUpdated: (p0) {
add(const ViewTitleBarEvent.reload());
},
);
}, },
reload: () async { reload: () async {
final List<ViewPB> ancestors = final List<ViewPB> ancestors =

View File

@ -143,6 +143,13 @@ class _ViewTitleState extends State<_ViewTitle> {
create: (_) => create: (_) =>
ViewTitleBloc(view: widget.view)..add(const ViewTitleEvent.initial()), ViewTitleBloc(view: widget.view)..add(const ViewTitleEvent.initial()),
child: BlocConsumer<ViewTitleBloc, ViewTitleState>( child: BlocConsumer<ViewTitleBloc, ViewTitleState>(
listenWhen: (previous, current) {
if (previous.view == null || current.view == null) {
return false;
}
return previous.view != current.view;
},
listener: (_, state) { listener: (_, state) {
_resetTextEditingController(state); _resetTextEditingController(state);
widget.onUpdated(); widget.onUpdated();