feat: integrate postgres storage (#2604)

* chore: env config

* chore: get user workspace

* feat: enable postgres storage

* chore: add new env

* chore: add set env ffi

* chore: pass env before backend init

* chore: update

* fix: ci tests

* chore: commit the generate env file

* chore: remove unused import
This commit is contained in:
Nathan.fooo
2023-05-23 23:55:21 +08:00
committed by GitHub
parent 51a7954af7
commit 056e2d49d0
87 changed files with 1421 additions and 1131 deletions

View File

@ -334,7 +334,7 @@ pub(crate) async fn create_row_handler(
}
}
#[tracing::instrument(level = "trace", skip_all, err)]
// #[tracing::instrument(level = "trace", skip_all, err)]
pub(crate) async fn get_cell_handler(
data: AFPluginData<CellIdPB>,
manager: AFPluginState<Arc<DatabaseManager2>>,
@ -560,7 +560,6 @@ pub(crate) async fn set_layout_setting_handler(
Ok(())
}
#[tracing::instrument(level = "debug", skip(data, manager), err)]
pub(crate) async fn get_layout_setting_handler(
data: AFPluginData<DatabaseLayoutIdPB>,
manager: AFPluginState<Arc<DatabaseManager2>>,

View File

@ -3,7 +3,7 @@ use std::ops::Deref;
use std::sync::Arc;
use appflowy_integrate::collab_builder::AppFlowyCollabBuilder;
use appflowy_integrate::{RocksCollabDB, RocksDBConfig};
use appflowy_integrate::{CollabPersistenceConfig, RocksCollabDB};
use collab::core::collab::MutexCollab;
use collab_database::database::DatabaseData;
use collab_database::user::{UserDatabase as InnerUserDatabase, UserDatabaseCollabBuilder};
@ -51,7 +51,7 @@ impl DatabaseManager2 {
*self.user_database.lock() = Some(InnerUserDatabase::new(
user_id,
db,
RocksDBConfig::default(),
CollabPersistenceConfig::default(),
UserDatabaseCollabBuilderImpl(self.collab_builder.clone()),
));
// do nothing
@ -229,7 +229,7 @@ impl UserDatabaseCollabBuilder for UserDatabaseCollabBuilderImpl {
uid: i64,
object_id: &str,
db: Arc<RocksCollabDB>,
config: &RocksDBConfig,
config: &CollabPersistenceConfig,
) -> Arc<MutexCollab> {
self.0.build_with_config(uid, object_id, db, config)
}

View File

@ -3,8 +3,9 @@ use std::sync::Arc;
use collab_database::fields::Field;
use collab_database::rows::RowId;
use flowy_error::FlowyResult;
use flowy_error::{FlowyError, FlowyResult};
use lib_infra::future::{to_fut, Fut};
use tracing::trace;
use crate::entities::FieldType;
use crate::services::database_view::DatabaseViewData;
@ -42,9 +43,10 @@ pub async fn new_group_controller(
let fields = delegate.get_fields(&view_id, None).await;
let rows = delegate.get_rows(&view_id).await;
let layout = delegate.get_layout_for_view(&view_id);
trace!(?fields, ?rows, ?layout, "new_group_controller");
// Read the grouping field or find a new grouping field
let grouping_field = setting_reader
let mut grouping_field = setting_reader
.get_group_setting(&view_id)
.await
.and_then(|setting| {
@ -52,17 +54,25 @@ pub async fn new_group_controller(
.iter()
.find(|field| field.id == setting.field_id)
.cloned()
})
.unwrap_or_else(|| find_new_grouping_field(&fields, &layout).unwrap());
});
make_group_controller(
view_id,
grouping_field,
rows,
setting_reader,
setting_writer,
)
.await
if grouping_field.is_none() {
grouping_field = find_new_grouping_field(&fields, &layout);
}
match grouping_field {
None => Err(FlowyError::internal().context("No grouping field found".to_owned())),
Some(_) => {
make_group_controller(
view_id,
grouping_field.unwrap(),
rows,
setting_reader,
setting_writer,
)
.await
},
}
}
pub(crate) struct GroupSettingReaderImpl(pub Arc<dyn DatabaseViewData>);

View File

@ -7,15 +7,9 @@ use strum::IntoEnumIterator;
use strum_macros::EnumIter;
lazy_static! {
pub static ref CURRENCY_SYMBOL: Vec<String> = sorted_symbol();
}
fn sorted_symbol() -> Vec<String> {
let mut symbols = NumberFormat::iter()
pub static ref CURRENCY_SYMBOL: Vec<String> = NumberFormat::iter()
.map(|format| format.symbol())
.collect::<Vec<String>>();
symbols.sort_by(|a, b| b.len().cmp(&a.len()));
symbols
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumIter, Serialize, Deserialize)]

View File

@ -137,9 +137,7 @@ impl NumberTypeOption {
};
match Decimal::from_str(&num_str) {
Ok(decimal, ..) => {
return Ok(NumberCellFormat::from_decimal(decimal));
},
Ok(decimal, ..) => Ok(NumberCellFormat::from_decimal(decimal)),
Err(_) => Ok(NumberCellFormat::new()),
}
}

View File

@ -27,7 +27,7 @@ impl NumberCellFormat {
return Ok(Self::default());
}
// If the first char is not '-', then it is a sign.
let sign_positive = match num_str.find("-") {
let sign_positive = match num_str.find('-') {
None => true,
Some(offset) => offset != 0,
};

View File

@ -162,7 +162,7 @@ where
) {
if let Some(cell_data_cache) = self.cell_data_cache.as_ref() {
let field_type = FieldType::from(field.field_type);
let key = CellDataCacheKey::new(field, field_type.clone(), cell);
let key = CellDataCacheKey::new(field, field_type, cell);
// tracing::trace!(
// "Cell cache update: field_type:{}, cell: {:?}, cell_data: {:?}",
// field_type,

View File

@ -85,7 +85,7 @@ impl SortController {
self.gen_task(task_type, QualityOfService::Background).await;
}
#[tracing::instrument(name = "process_sort_task", level = "debug", skip_all, err)]
// #[tracing::instrument(name = "process_sort_task", level = "trace", skip_all, err)]
pub async fn process(&mut self, predicate: &str) -> FlowyResult<()> {
let event_type = SortEvent::from_str(predicate).unwrap();
let mut rows = self.delegate.get_rows(&self.view_id).await;