fix: init database row init (#6127)

This commit is contained in:
Nathan.fooo 2024-08-30 22:12:20 +08:00 committed by GitHub
parent 3324e7837b
commit 8139065113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 18 additions and 0 deletions

View File

@ -306,6 +306,8 @@ class MobileRowDetailPageContentState
viewId: viewId, viewId: viewId,
rowCache: rowCache, rowCache: rowCache,
); );
rowController.initialize();
cellBuilder = EditableCellBuilder( cellBuilder = EditableCellBuilder(
databaseController: widget.databaseController, databaseController: widget.databaseController,
); );

View File

@ -35,6 +35,8 @@ class RelatedRowDetailPageBloc
on<RelatedRowDetailPageEvent>((event, emit) async { on<RelatedRowDetailPageEvent>((event, emit) async {
event.when( event.when(
didInitialize: (databaseController, rowController) { didInitialize: (databaseController, rowController) {
rowController.initialize();
state.maybeWhen( state.maybeWhen(
ready: (_, oldRowController) async { ready: (_, oldRowController) async {
await oldRowController.dispose(); await oldRowController.dispose();
@ -93,6 +95,7 @@ class RelatedRowDetailPageBloc
viewId: inlineView.id, viewId: inlineView.id,
rowCache: databaseController.rowCache, rowCache: databaseController.rowCache,
); );
add( add(
RelatedRowDetailPageEvent.didInitialize( RelatedRowDetailPageEvent.didInitialize(
databaseController, databaseController,

View File

@ -38,6 +38,9 @@ class RowController {
List<CellContext> loadCells() => _rowCache.loadCells(rowMeta); List<CellContext> loadCells() => _rowCache.loadCells(rowMeta);
/// This method must be called to initialize the row controller; otherwise, the row will not sync between devices.
/// When creating a row controller, calling [initialize] immediately may not be necessary.
/// Only call [initialize] when the row becomes visible. This approach helps reduce unnecessary sync operations.
Future<void> initialize() async { Future<void> initialize() async {
await _rowBackendSvc.initRow(rowMeta.id); await _rowBackendSvc.initRow(rowMeta.id);
unawaited( unawaited(

View File

@ -397,6 +397,7 @@ class HiddenGroupPopupItemList extends StatelessWidget {
viewId: viewId, viewId: viewId,
rowCache: rowCache, rowCache: rowCache,
); );
rowController.initialize();
final databaseController = final databaseController =
context.read<BoardBloc>().databaseController; context.read<BoardBloc>().databaseController;

View File

@ -29,6 +29,8 @@ class CalendarEventEditorBloc
(event, emit) async { (event, emit) async {
await event.when( await event.when(
initial: () { initial: () {
rowController.initialize();
_startListening(); _startListening();
final primaryFieldId = fieldController.fieldInfos final primaryFieldId = fieldController.fieldInfos
.firstWhere((fieldInfo) => fieldInfo.isPrimary) .firstWhere((fieldInfo) => fieldInfo.isPrimary)

View File

@ -20,6 +20,8 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
_dispatch(); _dispatch();
_startListening(); _startListening();
_init(); _init();
rowController.initialize();
} }
final FieldController fieldController; final FieldController fieldController;

View File

@ -32,6 +32,7 @@ class CardBloc extends Bloc<CardEvent, CardState> {
rowController.rowMeta, rowController.rowMeta,
), ),
) { ) {
rowController.initialize();
_dispatch(); _dispatch();
} }

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:appflowy/plugins/database/application/database_controller.dart'; import 'package:appflowy/plugins/database/application/database_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_controller.dart'; import 'package:appflowy/plugins/database/application/row/row_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart'; import 'package:appflowy/plugins/database/application/row/row_service.dart';
@ -87,6 +89,8 @@ class DatabaseDocumentTitleBloc
viewId: view.id, viewId: view.id,
rowCache: databaseController.rowCache, rowCache: databaseController.rowCache,
); );
unawaited(rowController.initialize());
final primaryFieldId = final primaryFieldId =
await FieldBackendService.getPrimaryField(viewId: view.id).fold( await FieldBackendService.getPrimaryField(viewId: view.id).fold(
(primaryField) => primaryField.id, (primaryField) => primaryField.id,