mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: format code
This commit is contained in:
parent
c35db5c2a2
commit
dcf8fd538d
@ -31,7 +31,7 @@ use flowy_task::TaskDispatcher;
|
|||||||
|
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{RwLock, RwLockWriteGuard, TryLockError};
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub trait DatabaseUser: Send + Sync {
|
pub trait DatabaseUser: Send + Sync {
|
||||||
fn user_id(&self) -> Result<String, FlowyError>;
|
fn user_id(&self) -> Result<String, FlowyError>;
|
||||||
@ -146,24 +146,25 @@ impl DatabaseManager {
|
|||||||
let database_info = self.database_ref_indexer.get_database_with_view(view_id)?;
|
let database_info = self.database_ref_indexer.get_database_with_view(view_id)?;
|
||||||
tracing::Span::current().record("database_id", &database_info.database_id);
|
tracing::Span::current().record("database_id", &database_info.database_id);
|
||||||
|
|
||||||
match self.editors_by_database_id.try_write() {
|
// Create a temporary reference database_editor in case of holding the write lock
|
||||||
Ok(mut write_guard) => {
|
// of editors_by_database_id too long.
|
||||||
if let Some(database_editor) = write_guard.remove(&database_info.database_id) {
|
let database_editor = self
|
||||||
database_editor.close_view_editor(view_id).await;
|
.editors_by_database_id
|
||||||
if database_editor.number_of_ref_views().await == 0 {
|
.write()
|
||||||
database_editor.dispose().await;
|
.await
|
||||||
} else {
|
.remove(&database_info.database_id);
|
||||||
self
|
|
||||||
.editors_by_database_id
|
if let Some(database_editor) = database_editor {
|
||||||
.write()
|
database_editor.close_view_editor(view_id).await;
|
||||||
.await
|
if database_editor.number_of_ref_views().await == 0 {
|
||||||
.insert(database_info.database_id, database_editor);
|
database_editor.dispose().await;
|
||||||
}
|
} else {
|
||||||
}
|
self
|
||||||
},
|
.editors_by_database_id
|
||||||
Err(_) => {
|
.write()
|
||||||
tracing::error!("Try to get the lock of editors_by_database_id failed");
|
.await
|
||||||
},
|
.insert(database_info.database_id, database_editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -28,9 +28,7 @@ use flowy_error::FlowyResult;
|
|||||||
use flowy_revision::RevisionManager;
|
use flowy_revision::RevisionManager;
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use flowy_task::TaskDispatcher;
|
use flowy_task::TaskDispatcher;
|
||||||
use lib_infra::async_trait::async_trait;
|
|
||||||
use lib_infra::future::Fut;
|
use lib_infra::future::Fut;
|
||||||
use lib_infra::ref_map::RefCountValue;
|
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -182,8 +180,8 @@ impl DatabaseViewEditor {
|
|||||||
pub async fn close(&self) {
|
pub async fn close(&self) {
|
||||||
self.rev_manager.generate_snapshot().await;
|
self.rev_manager.generate_snapshot().await;
|
||||||
self.rev_manager.close().await;
|
self.rev_manager.close().await;
|
||||||
self.filter_controller.close().await;
|
|
||||||
self.sort_controller.write().await.close().await;
|
self.sort_controller.write().await.close().await;
|
||||||
|
// self.filter_controller.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_block_event(&self, event: Cow<'_, DatabaseBlockEvent>) {
|
pub async fn handle_block_event(&self, event: Cow<'_, DatabaseBlockEvent>) {
|
||||||
@ -869,13 +867,6 @@ pub(crate) async fn get_cells_for_field(
|
|||||||
Ok(cells)
|
Ok(cells)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl RefCountValue for DatabaseViewEditor {
|
|
||||||
async fn did_remove(&self) {
|
|
||||||
self.close().await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn new_group_controller(
|
async fn new_group_controller(
|
||||||
user_id: String,
|
user_id: String,
|
||||||
view_id: String,
|
view_id: String,
|
||||||
|
@ -20,8 +20,8 @@ use flowy_error::FlowyResult;
|
|||||||
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use lib_infra::future::Fut;
|
use lib_infra::future::Fut;
|
||||||
use lib_infra::ref_map::RefCountHashMap;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{broadcast, RwLock};
|
use tokio::sync::{broadcast, RwLock};
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ use tokio::sync::{broadcast, RwLock};
|
|||||||
pub struct DatabaseViews {
|
pub struct DatabaseViews {
|
||||||
user: Arc<dyn DatabaseUser>,
|
user: Arc<dyn DatabaseUser>,
|
||||||
delegate: Arc<dyn DatabaseViewData>,
|
delegate: Arc<dyn DatabaseViewData>,
|
||||||
view_editors: Arc<RwLock<RefCountHashMap<Arc<DatabaseViewEditor>>>>,
|
view_editors: Arc<RwLock<HashMap<String, Arc<DatabaseViewEditor>>>>,
|
||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ impl DatabaseViews {
|
|||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
block_event_rx: broadcast::Receiver<DatabaseBlockEvent>,
|
block_event_rx: broadcast::Receiver<DatabaseBlockEvent>,
|
||||||
) -> FlowyResult<Self> {
|
) -> FlowyResult<Self> {
|
||||||
let view_editors = Arc::new(RwLock::new(RefCountHashMap::default()));
|
let view_editors = Arc::new(RwLock::new(HashMap::default()));
|
||||||
listen_on_database_block_event(block_event_rx, view_editors.clone());
|
listen_on_database_block_event(block_event_rx, view_editors.clone());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
user,
|
user,
|
||||||
@ -61,7 +61,9 @@ impl DatabaseViews {
|
|||||||
|
|
||||||
pub async fn close(&self, view_id: &str) {
|
pub async fn close(&self, view_id: &str) {
|
||||||
if let Ok(mut view_editors) = self.view_editors.try_write() {
|
if let Ok(mut view_editors) = self.view_editors.try_write() {
|
||||||
view_editors.remove(view_id).await;
|
if let Some(view_editor) = view_editors.remove(view_id) {
|
||||||
|
view_editor.close().await;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::error!("Try to get the lock of view_editors failed");
|
tracing::error!("Try to get the lock of view_editors failed");
|
||||||
}
|
}
|
||||||
@ -273,7 +275,7 @@ impl DatabaseViews {
|
|||||||
pub async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<DatabaseViewEditor>> {
|
pub async fn get_view_editor(&self, view_id: &str) -> FlowyResult<Arc<DatabaseViewEditor>> {
|
||||||
debug_assert!(!view_id.is_empty());
|
debug_assert!(!view_id.is_empty());
|
||||||
if let Some(editor) = self.view_editors.read().await.get(view_id) {
|
if let Some(editor) = self.view_editors.read().await.get(view_id) {
|
||||||
return Ok(editor);
|
return Ok(editor.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
tracing::trace!("{:p} create view:{} editor", self, view_id);
|
tracing::trace!("{:p} create view:{} editor", self, view_id);
|
||||||
@ -346,7 +348,7 @@ pub async fn make_database_view_rev_manager(
|
|||||||
|
|
||||||
fn listen_on_database_block_event(
|
fn listen_on_database_block_event(
|
||||||
mut block_event_rx: broadcast::Receiver<DatabaseBlockEvent>,
|
mut block_event_rx: broadcast::Receiver<DatabaseBlockEvent>,
|
||||||
view_editors: Arc<RwLock<RefCountHashMap<Arc<DatabaseViewEditor>>>>,
|
view_editors: Arc<RwLock<HashMap<String, Arc<DatabaseViewEditor>>>>,
|
||||||
) {
|
) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
@ -358,7 +360,7 @@ fn listen_on_database_block_event(
|
|||||||
} else {
|
} else {
|
||||||
Cow::Borrowed(&event)
|
Cow::Borrowed(&event)
|
||||||
};
|
};
|
||||||
for view_editor in view_editors.iter() {
|
for view_editor in view_editors {
|
||||||
view_editor.handle_block_event(event.clone()).await;
|
view_editor.handle_block_event(event.clone()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,12 +74,11 @@ impl FilterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn close(&self) {
|
pub async fn close(&self) {
|
||||||
self
|
if let Ok(mut task_scheduler) = self.task_scheduler.try_write() {
|
||||||
.task_scheduler
|
task_scheduler.unregister_handler(&self.handler_id).await;
|
||||||
.write()
|
} else {
|
||||||
.await
|
tracing::error!("Try to get the lock of task_scheduler failed");
|
||||||
.unregister_handler(&self.handler_id)
|
}
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "schedule_filter_task", level = "trace", skip(self))]
|
#[tracing::instrument(name = "schedule_filter_task", level = "trace", skip(self))]
|
||||||
|
@ -64,7 +64,7 @@ impl SortController {
|
|||||||
|
|
||||||
pub async fn close(&self) {
|
pub async fn close(&self) {
|
||||||
if let Ok(mut task_scheduler) = self.task_scheduler.try_write() {
|
if let Ok(mut task_scheduler) = self.task_scheduler.try_write() {
|
||||||
// task_scheduler.unregister_handler(&self.handler_id).await;
|
task_scheduler.unregister_handler(&self.handler_id).await;
|
||||||
} else {
|
} else {
|
||||||
tracing::error!("Try to get the lock of task_scheduler failed");
|
tracing::error!("Try to get the lock of task_scheduler failed");
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ use crate::queue::TaskQueue;
|
|||||||
use crate::store::TaskStore;
|
use crate::store::TaskStore;
|
||||||
use crate::{Task, TaskContent, TaskId, TaskState};
|
use crate::{Task, TaskContent, TaskId, TaskState};
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use lib_infra::async_trait::async_trait;
|
|
||||||
use lib_infra::future::BoxResultFuture;
|
use lib_infra::future::BoxResultFuture;
|
||||||
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
Loading…
Reference in New Issue
Block a user