Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: remove cancel get rows (#6320)

Nathan.foooc2b194b1d2dd
diff --git a/frontend/appflowy_flutter/packages/appflowy_backend/lib/log.dart b/frontend/appflowy_flutter/packages/appflowy_backend/lib/log.dart
index 4e52ba2c82..f7db1e6777 100644
--- a/frontend/appflowy_flutter/packages/appflowy_backend/lib/log.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_backend/lib/log.dart
@@ -9,43 +9,67 @@ import 'ffi.dart';
class Log {
static final shared = Log();
- // ignore: unused_field
late Logger _logger;
Log() {
_logger = Logger(
printer: PrettyPrinter(
- methodCount: 2, // number of method calls to be displayed
- errorMethodCount:
- 8, // number of method calls if stacktrace is provided
- lineLength: 120, // width of the output
- colors: true, // Colorful log messages
- printEmojis: true, // Print an emoji for each log message
- dateTimeFormat:
- DateTimeFormat.none // Should each log print contain a timestamp
- ),
+ methodCount: 2, // Number of method calls to be displayed
+ errorMethodCount: 8, // Number of method calls if stacktrace is provided
+ lineLength: 120, // Width of the output
+ colors: true, // Colorful log messages
+ printEmojis: true, // Print an emoji for each log message
+ ),
level: kDebugMode ? Level.trace : Level.info,
);
}
+ // Generic internal logging function to reduce code duplication
+ static void _log(Level level, int rustLevel, dynamic msg,
+ [dynamic error, StackTrace? stackTrace]) {
+ if (kDebugMode) {
+ switch (level) {
+ case Level.info:
+ shared._logger.i(msg, stackTrace: stackTrace);
+ break;
+ case Level.debug:
+ shared._logger.d(msg, stackTrace: stackTrace);
+ break;
+ case Level.warning:
+ shared._logger.w(msg, stackTrace: stackTrace);
+ break;
+ case Level.error:
+ shared._logger.e(msg, stackTrace: stackTrace);
+ break;
+ case Level.trace:
+ shared._logger.t(msg, stackTrace: stackTrace);
+ break;
+ default:
+ shared._logger.log(level, msg, stackTrace: stackTrace);
+ }
+ }
+ String formattedMessage = _formatMessageWithStackTrace(msg, stackTrace);
+ rust_log(rustLevel, toNativeUtf8(formattedMessage));
+ }
+
static void info(dynamic msg, [dynamic error, StackTrace? stackTrace]) {
- rust_log(0, toNativeUtf8(msg));
+ _log(Level.info, 0, msg, error, stackTrace);
}
static void debug(dynamic msg, [dynamic error, StackTrace? stackTrace]) {
- rust_log(1, toNativeUtf8(msg));
+ _log(Level.debug, 1, msg, error, stackTrace);
}
static void warn(dynamic msg, [dynamic error, StackTrace? stackTrace]) {
- rust_log(3, toNativeUtf8(msg));
+ _log(Level.warning, 3, msg, error, stackTrace);
}
static void trace(dynamic msg, [dynamic error, StackTrace? stackTrace]) {
- rust_log(2, toNativeUtf8(msg));
+ _log(Level.trace, 2, msg, error, stackTrace);
}
static void error(dynamic msg, [dynamic error, StackTrace? stackTrace]) {
- rust_log(4, toNativeUtf8(msg));
+ _log(Level.error, 4, msg, error, stackTrace);
}
}
@@ -53,6 +77,14 @@ bool isReleaseVersion() {
return kReleaseMode;
}
+// Utility to convert a message to native Utf8 (used in rust_log)
Pointer<ffi.Utf8> toNativeUtf8(dynamic msg) {
return "$msg".toNativeUtf8();
}
+
+String _formatMessageWithStackTrace(dynamic msg, StackTrace? stackTrace) {
+ if (stackTrace != null) {
+ return "$msg\nStackTrace:\n$stackTrace"; // Append the stack trace to the message
+ }
+ return msg.toString();
+ }
diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
index 1a5b447577..3b0c35d2e0 100644
--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
@@ -63,6 +63,7 @@ pub struct DatabaseEditor {
collab_builder: Arc<AppFlowyCollabBuilder>,
is_loading_rows: ArcSwapOption<broadcast::Sender<()>>,
opening_ret_txs: Arc<RwLock<Vec<OpenDatabaseResult>>>,
+ #[allow(dead_code)]
database_cancellation: Arc<RwLock<Option<CancellationToken>>>,
un_finalized_rows_cancellation: Arc<ArcSwapOption<CancellationToken>>,
finalized_rows: Arc<moka::future::Cache<String, Weak<RwLock<DatabaseRow>>>>,
@@ -1932,17 +1933,8 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {
let view_id = view_id.to_string();
trace!("{} has total row orders: {}", view_id, row_orders.len());
let mut all_rows = vec![];
- let cancellation = self
- .database_cancellation
- .read()
- .await
- .as_ref()
- .map(|c| c.clone());
-
let read_guard = self.database.read().await;
- let rows_stream = read_guard
- .get_rows_from_row_orders(&row_orders, cancellation)
- .await;
+ let rows_stream = read_guard.get_rows_from_row_orders(&row_orders, None).await;
pin_mut!(rows_stream);
while let Some(result) = rows_stream.next().await {
diff --git a/frontend/rust-lib/flowy-database2/src/services/group/controller.rs b/frontend/rust-lib/flowy-database2/src/services/group/controller.rs
index aa10055e02..077fc41a37 100644
--- a/frontend/rust-lib/flowy-database2/src/services/group/controller.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/group/controller.rs
@@ -63,8 +63,7 @@ where
.get_type_option::<T>(&field_type)
.unwrap_or_else(|| T::from(default_type_option_data_from_type(field_type)));
- // TODO(nathan): remove block_on
- let generated_groups = block_on(G::build(grouping_field, &configuration, &type_option));
+ let generated_groups = G::build(grouping_field, &configuration, &type_option).await;
let _ = configuration.init_groups(generated_groups)?;
Ok(Self {
diff --git a/frontend/rust-lib/flowy-database2/src/services/group/entities.rs b/frontend/rust-lib/flowy-database2/src/services/group/entities.rs
index b27c947e7d..296a9960f7 100644
--- a/frontend/rust-lib/flowy-database2/src/services/group/entities.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/group/entities.rs
@@ -4,6 +4,7 @@ use collab_database::database::gen_database_group_id;
use collab_database::rows::{Row, RowId};
use collab_database::views::{GroupMap, GroupMapBuilder, GroupSettingBuilder, GroupSettingMap};
use serde::{Deserialize, Serialize};
+use std::fmt::Display;
use std::sync::Arc;
#[derive(Debug, Clone, Default, Deserialize)]
@@ -105,6 +106,12 @@ pub struct GroupData {
pub(crate) rows: Vec<Row>,
}
+impl Display for GroupData {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "GroupData:{}, {} rows", self.id, self.rows.len())
+ }
+}
+
impl GroupData {
pub fn new(id: String, field_id: String, is_visible: bool) -> Self {
let is_default = id == field_id;
diff --git a/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs b/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs
index f8fcd61cb2..009b137a3d 100644
--- a/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/group/group_builder.rs
@@ -4,8 +4,8 @@ use std::sync::Arc;
use async_trait::async_trait;
use collab_database::fields::Field;
use collab_database::rows::{Cell, Row, RowId};
-
use flowy_error::FlowyResult;
+use tracing::trace;
use crate::entities::FieldType;
use crate::services::field::TypeOption;
@@ -144,14 +144,18 @@ where
// Separates the rows into different groups
let row_details = delegate.get_all_rows(view_id).await;
-
let rows = row_details
.iter()
.map(|row| row.as_ref())
.collect::<Vec<_>>();
group_controller.fill_groups(rows.as_slice(), &grouping_field)?;
-
+ #[cfg(feature = "verbose_log")]
+ {
+ for group in group_controller.get_all_groups() {
+ trace!("[Database]: group: {}", group);
+ }
+ }
Ok(group_controller)
}