feat: enable debug logs in internal build (#5713)

This commit is contained in:
Lucas.Xu 2024-07-10 13:55:40 +08:00 committed by GitHub
parent c006e29afc
commit 0fe383e538
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 66 additions and 22 deletions

View File

@ -29,4 +29,11 @@ abstract class Env {
defaultValue: '', defaultValue: '',
) )
static const String afCloudUrl = _Env.afCloudUrl; static const String afCloudUrl = _Env.afCloudUrl;
@EnviedField(
obfuscate: false,
varName: 'INTERNAL_BUILD',
defaultValue: '',
)
static const String internalBuild = _Env.internalBuild;
} }

View File

@ -18,6 +18,7 @@ import 'package:appflowy/util/color_to_hex_string.dart';
import 'package:appflowy/util/debounce.dart'; import 'package:appflowy/util/debounce.dart';
import 'package:appflowy/util/throttle.dart'; import 'package:appflowy/util/throttle.dart';
import 'package:appflowy/workspace/application/view/view_listener.dart'; import 'package:appflowy/workspace/application/view/view_listener.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart'; import 'package:appflowy_backend/protobuf/flowy-document/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
@ -37,6 +38,8 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'document_bloc.freezed.dart'; part 'document_bloc.freezed.dart';
bool enableDocumentInternalLog = false;
class DocumentBloc extends Bloc<DocumentEvent, DocumentState> { class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
DocumentBloc({ DocumentBloc({
required this.documentId, required this.documentId,
@ -212,6 +215,10 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
} }
Future<EditorState?> _initAppFlowyEditorState(DocumentDataPB data) async { Future<EditorState?> _initAppFlowyEditorState(DocumentDataPB data) async {
if (enableDocumentInternalLog) {
Log.info('document data: ${data.toProto3Json()}');
}
final document = data.toDocument(); final document = data.toDocument();
if (document == null) { if (document == null) {
assert(false, 'document is null'); assert(false, 'document is null');

View File

@ -180,6 +180,8 @@ extension NodeToBlock on Node {
String? parentId, String? parentId,
String? childrenId, String? childrenId,
Attributes? attributes, Attributes? attributes,
String? externalId,
String? externalType,
}) { }) {
assert(id.isNotEmpty); assert(id.isNotEmpty);
final block = BlockPB.create() final block = BlockPB.create()
@ -192,6 +194,12 @@ extension NodeToBlock on Node {
if (parentId != null && parentId.isNotEmpty) { if (parentId != null && parentId.isNotEmpty) {
block.parentId = parentId; block.parentId = parentId;
} }
if (externalId != null && externalId.isNotEmpty) {
block.externalId = externalId;
}
if (externalType != null && externalType.isNotEmpty) {
block.externalType = externalType;
}
return block; return block;
} }

View File

@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart'; import 'package:appflowy/plugins/document/application/document_data_pb_extension.dart';
import 'package:appflowy/plugins/document/application/document_service.dart'; import 'package:appflowy/plugins/document/application/document_service.dart';
import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/log.dart';
@ -21,6 +22,8 @@ import 'package:appflowy_editor/appflowy_editor.dart'
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:nanoid/nanoid.dart'; import 'package:nanoid/nanoid.dart';
const _kExternalTextType = 'text';
/// Uses to adjust the data structure between the editor and the backend. /// Uses to adjust the data structure between the editor and the backend.
/// ///
/// The editor uses a tree structure to represent the document, while the backend uses a flat structure. /// The editor uses a tree structure to represent the document, while the backend uses a flat structure.
@ -34,11 +37,9 @@ class TransactionAdapter {
final DocumentService documentService; final DocumentService documentService;
final String documentId; final String documentId;
final bool _enableDebug = false;
Future<void> apply(Transaction transaction, EditorState editorState) async { Future<void> apply(Transaction transaction, EditorState editorState) async {
final stopwatch = Stopwatch()..start(); final stopwatch = Stopwatch()..start();
if (_enableDebug) { if (enableDocumentInternalLog) {
Log.debug('transaction => ${transaction.toJson()}'); Log.debug('transaction => ${transaction.toJson()}');
} }
final actions = transaction.operations final actions = transaction.operations
@ -60,8 +61,10 @@ class TransactionAdapter {
textId: payload.textId, textId: payload.textId,
delta: payload.delta, delta: payload.delta,
); );
if (_enableDebug) { if (enableDocumentInternalLog) {
Log.debug('create external text: ${payload.delta}'); Log.debug(
'[editor_transaction_adapter] create external text: ${payload.delta}',
);
} }
} else if (type == TextDeltaType.update) { } else if (type == TextDeltaType.update) {
await documentService.updateExternalText( await documentService.updateExternalText(
@ -69,8 +72,10 @@ class TransactionAdapter {
textId: payload.textId, textId: payload.textId,
delta: payload.delta, delta: payload.delta,
); );
if (_enableDebug) { if (enableDocumentInternalLog) {
Log.debug('update external text: ${payload.delta}'); Log.debug(
'[editor_transaction_adapter] update external text: ${payload.delta}',
);
} }
} }
} }
@ -82,9 +87,9 @@ class TransactionAdapter {
); );
final elapsed = stopwatch.elapsedMilliseconds; final elapsed = stopwatch.elapsedMilliseconds;
stopwatch.stop(); stopwatch.stop();
if (_enableDebug) { if (enableDocumentInternalLog) {
Log.debug( Log.debug(
'apply transaction cost: total $elapsed ms, converter action $actionCostTime ms, apply action ${elapsed - actionCostTime} ms', '[editor_transaction_adapter] apply transaction cost: total $elapsed ms, converter action $actionCostTime ms, apply action ${elapsed - actionCostTime} ms',
); );
} }
} }
@ -136,8 +141,9 @@ extension on InsertOperation {
// create the external text if the node contains the delta in its data. // create the external text if the node contains the delta in its data.
final delta = node.delta; final delta = node.delta;
TextDeltaPayloadPB? textDeltaPayloadPB; TextDeltaPayloadPB? textDeltaPayloadPB;
String? textId;
if (delta != null) { if (delta != null) {
final textId = nanoid(6); textId = nanoid(6);
textDeltaPayloadPB = TextDeltaPayloadPB( textDeltaPayloadPB = TextDeltaPayloadPB(
documentId: documentId, documentId: documentId,
@ -148,13 +154,17 @@ extension on InsertOperation {
// sync the text id to the node // sync the text id to the node
node.externalValues = ExternalValues( node.externalValues = ExternalValues(
externalId: textId, externalId: textId,
externalType: 'text', externalType: _kExternalTextType,
); );
} }
// remove the delta from the data when the incremental update is stable. // remove the delta from the data when the incremental update is stable.
final payload = BlockActionPayloadPB() final payload = BlockActionPayloadPB()
..block = node.toBlock(childrenId: nanoid(6)) ..block = node.toBlock(
childrenId: nanoid(6),
externalId: textId,
externalType: textId != null ? _kExternalTextType : null,
)
..parentId = parentId ..parentId = parentId
..prevId = prevId; ..prevId = prevId;
@ -248,7 +258,7 @@ extension on UpdateOperation {
node.externalValues = ExternalValues( node.externalValues = ExternalValues(
externalId: textId, externalId: textId,
externalType: 'text', externalType: _kExternalTextType,
); );
actions.add( actions.add(

View File

@ -27,7 +27,6 @@ import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart'; import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_migration.dart'; import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_migration.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart'; import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart' import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
show UserProfilePB; show UserProfilePB;
@ -371,11 +370,6 @@ class _SidebarState extends State<_Sidebar> {
final sidebarSectionBloc = context.watch<SidebarSectionsBloc>(); final sidebarSectionBloc = context.watch<SidebarSectionsBloc>();
final containsSpace = sidebarSectionBloc.state.containsSpace; final containsSpace = sidebarSectionBloc.state.containsSpace;
Log.info('fetch the space info from sidebar section: $containsSpace');
Log.info(
'fetch the space info from space: ${spaceState.spaces.isNotEmpty}',
);
if (containsSpace && spaceState.spaces.isEmpty) { if (containsSpace && spaceState.spaces.isEmpty) {
context.read<SpaceBloc>().add(const SpaceEvent.didReceiveSpaceUpdate()); context.read<SpaceBloc>().add(const SpaceEvent.didReceiveSpaceUpdate());
} }

View File

@ -1,9 +1,12 @@
import 'package:appflowy/core/helpers/url_launcher.dart'; import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/env/env.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/startup/tasks/rust_sdk.dart'; import 'package:appflowy/startup/tasks/rust_sdk.dart';
import 'package:appflowy/util/theme_extension.dart'; import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart'; import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart'; import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart';
@ -203,9 +206,24 @@ class FlowyVersionDescription extends CustomActionCell {
thickness: 1.0, thickness: 1.0,
), ),
const VSpace(6), const VSpace(6),
FlowyText( GestureDetector(
"$appName $version", behavior: HitTestBehavior.opaque,
color: Theme.of(context).hintColor, onDoubleTap: () {
if (Env.internalBuild != '1') {
return;
}
enableDocumentInternalLog = !enableDocumentInternalLog;
showToastNotification(
context,
message: enableDocumentInternalLog
? 'Enabled Internal Log'
: 'Disabled Internal Log',
);
},
child: FlowyText(
'$appName $version',
color: Theme.of(context).hintColor,
),
), ),
], ],
).padding( ).padding(