fix: calculate value

This commit is contained in:
nathan 2024-10-03 13:27:35 +08:00
parent bec1668272
commit 90cf10e2c4
12 changed files with 95 additions and 154 deletions

View File

@ -862,14 +862,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
functions_client:
dependency: transitive
description:
name: functions_client
sha256: e63f49cd3b41727f47b3bde284a11a4ac62839e0604f64077d4257487510e484
url: "https://pub.dev"
source: hosted
version: "2.3.2"
get_it:
dependency: "direct main"
description:
@ -902,14 +894,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.2.1"
gotrue:
dependency: transitive
description:
name: gotrue
sha256: "8703db795511f69194fe77125a0c838bbb6befc2f95717b6e40331784a8bdecb"
url: "https://pub.dev"
source: hosted
version: "2.8.4"
graphs:
dependency: transitive
description:
@ -1139,14 +1123,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.8.0"
jwt_decode:
dependency: transitive
description:
name: jwt_decode
sha256: d2e9f68c052b2225130977429d30f187aa1981d789c76ad104a32243cfdebfbb
url: "https://pub.dev"
source: hosted
version: "0.3.1"
keyboard_height_plugin:
dependency: "direct main"
description:
@ -1559,10 +1535,10 @@ packages:
dependency: transitive
description:
name: platform
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
version: "3.1.4"
plugin_platform_interface:
dependency: "direct dev"
description:
@ -1579,14 +1555,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.1"
postgrest:
dependency: transitive
description:
name: postgrest
sha256: c4197238601c7c3103b03a4bb77f2050b17d0064bf8b968309421abdebbb7f0e
url: "https://pub.dev"
source: hosted
version: "2.1.4"
process:
dependency: transitive
description:
@ -1635,14 +1603,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.2"
realtime_client:
dependency: transitive
description:
name: realtime_client
sha256: d897a65ee3b1b5ddc1cf606f0b83792262d38fd5679c2df7e38da29c977513da
url: "https://pub.dev"
source: hosted
version: "2.2.1"
recase:
dependency: transitive
description:
@ -1667,14 +1627,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.0"
retry:
dependency: transitive
description:
name: retry
sha256: "822e118d5b3aafed083109c72d5f484c6dc66707885e07c0fbcb8b986bba7efc"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
run_with_network_images:
dependency: "direct dev"
description:
@ -1961,14 +1913,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.1"
storage_client:
dependency: transitive
description:
name: storage_client
sha256: "28c147c805304dbc2b762becd1fc26ee0cb621ace3732b9ae61ef979aab8b367"
url: "https://pub.dev"
source: hosted
version: "2.0.3"
stream_channel:
dependency: transitive
description:
@ -1989,10 +1933,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.0"
string_validator:
dependency: "direct main"
description:
@ -2009,23 +1953,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.1"
supabase:
dependency: transitive
description:
name: supabase
sha256: "4ed1cf3298f39865c05b2d8557f92eb131a9b9af70e32e218672a0afce01a6bc"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
supabase_flutter:
dependency: "direct main"
description:
path: "packages/supabase_flutter"
ref: "9b05eea"
resolved-ref: "9b05eeac559a1f2da6289e1d70b3fa89e262fa3c"
url: "https://github.com/supabase/supabase-flutter"
source: git
version: "2.3.1"
super_clipboard:
dependency: "direct main"
description:
@ -2311,10 +2238,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.2.1"
watcher:
dependency: transitive
description:
@ -2403,14 +2330,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.2"
yet_another_json_isolate:
dependency: transitive
description:
name: yet_another_json_isolate
sha256: "47ed3900e6b0e4dfe378811a4402e85b7fc126a7daa94f840fef65ea9c8e46f4"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
sdks:
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"

View File

@ -5,10 +5,10 @@ use std::sync::Arc;
use collab_database::fields::Field;
use collab_database::rows::{Row, RowCell};
use flowy_error::FlowyResult;
use lib_infra::priority_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock as TokioRwLock;
use lib_infra::priority_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
use tracing::instrument;
use crate::entities::{
CalculationChangesetNotificationPB, CalculationPB, CalculationType, FieldType,
@ -278,6 +278,7 @@ impl CalculationsController {
}
}
#[instrument(level = "trace", skip_all)]
async fn get_updated_calculation(&self, calculation: Arc<Calculation>) -> Option<Calculation> {
let field_cells = self
.delegate

View File

@ -6,11 +6,11 @@ use collab_database::rows::RowCell;
use crate::entities::CalculationType;
use crate::services::field::TypeOptionCellExt;
pub struct CalculationsService {}
pub struct CalculationsService;
impl CalculationsService {
pub fn new() -> Self {
Self {}
Self
}
pub fn calculate(

View File

@ -1,9 +1,9 @@
use lib_infra::future::BoxResultFuture;
use crate::services::calculations::CalculationsController;
use async_trait::async_trait;
use lib_infra::priority_task::{TaskContent, TaskHandler};
use std::sync::Arc;
use crate::services::calculations::CalculationsController;
pub struct CalculationsTaskHandler {
handler_id: String,
calculations_controller: Arc<CalculationsController>,
@ -18,6 +18,7 @@ impl CalculationsTaskHandler {
}
}
#[async_trait]
impl TaskHandler for CalculationsTaskHandler {
fn handler_id(&self) -> &str {
&self.handler_id
@ -27,16 +28,14 @@ impl TaskHandler for CalculationsTaskHandler {
"CalculationsTaskHandler"
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), anyhow::Error> {
async fn run(&self, content: TaskContent) -> Result<(), anyhow::Error> {
let calculations_controller = self.calculations_controller.clone();
Box::pin(async move {
if let TaskContent::Text(predicate) = content {
calculations_controller
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
})
if let TaskContent::Text(predicate) = content {
calculations_controller
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
}
}

View File

@ -1976,13 +1976,11 @@ impl DatabaseViewOperation for DatabaseViewOperationImpl {
}
async fn get_cells_for_field(&self, view_id: &str, field_id: &str) -> Vec<Arc<RowCell>> {
let cells = self
.database
.read()
.await
.get_cells_for_field(view_id, field_id)
.await;
cells.into_iter().map(Arc::new).collect()
let editor = self.editor_by_view_id.read().await.get(view_id).cloned();
match editor {
None => vec![],
Some(editor) => editor.v_get_cells_for_field(field_id).await,
}
}
async fn get_cell_in_row(&self, field_id: &str, row_id: &RowId) -> Arc<RowCell> {

View File

@ -36,7 +36,7 @@ use crate::services::sort::{Sort, SortChangeset, SortController};
use collab_database::database::{gen_database_calculation_id, gen_database_sort_id, gen_row_id};
use collab_database::entity::DatabaseView;
use collab_database::fields::Field;
use collab_database::rows::{Cells, Row, RowDetail, RowId};
use collab_database::rows::{Cells, Row, RowCell, RowDetail, RowId};
use collab_database::views::{DatabaseLayout, RowOrder};
use dashmap::DashMap;
use flowy_error::{FlowyError, FlowyResult};
@ -376,6 +376,27 @@ impl DatabaseViewEditor {
rows
}
pub async fn v_get_cells_for_field(&self, field_id: &str) -> Vec<Arc<RowCell>> {
let row_orders = self.delegate.get_all_row_orders(&self.view_id).await;
let rows = self.delegate.get_all_rows(&self.view_id, row_orders).await;
let rows = self.v_filter_rows(rows).await;
let rows = rows
.into_iter()
.filter_map(|row| {
row.cells.get(field_id).map(|cell| {
let cell = RowCell::new(row.id.clone(), Some(cell.clone()));
Arc::new(cell)
})
})
.collect::<Vec<_>>();
trace!(
"[Database]: get cells for field: {}, total rows:{}",
field_id,
rows.len()
);
rows
}
pub async fn v_get_row(&self, row_id: &RowId) -> Option<(usize, Arc<RowDetail>)> {
self.delegate.get_row_detail(&self.view_id, row_id).await
}

View File

@ -18,7 +18,7 @@ impl DateFilterPB {
let timestamp = if self.condition.is_filter_on_start_timestamp() {
cell_data.timestamp
} else {
cell_data.end_timestamp.or_else(|| cell_data.timestamp)
cell_data.end_timestamp.or(cell_data.timestamp)
};
Some(strategy.filter(timestamp))

View File

@ -1,5 +1,6 @@
use crate::services::filter::FilterController;
use lib_infra::future::BoxResultFuture;
use async_trait::async_trait;
use lib_infra::priority_task::{TaskContent, TaskHandler};
use std::sync::Arc;
@ -17,6 +18,7 @@ impl FilterTaskHandler {
}
}
#[async_trait]
impl TaskHandler for FilterTaskHandler {
fn handler_id(&self) -> &str {
&self.handler_id
@ -26,16 +28,14 @@ impl TaskHandler for FilterTaskHandler {
"FilterTaskHandler"
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), anyhow::Error> {
async fn run(&self, content: TaskContent) -> Result<(), anyhow::Error> {
let filter_controller = self.filter_controller.clone();
Box::pin(async move {
if let TaskContent::Text(predicate) = content {
filter_controller
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
})
if let TaskContent::Text(predicate) = content {
filter_controller
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
}
}

View File

@ -6,6 +6,7 @@ use std::sync::Arc;
use collab_database::fields::Field;
use collab_database::rows::{Cell, Row, RowId};
use rayon::prelude::ParallelSliceMut;
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock as TokioRwLock;

View File

@ -1,5 +1,6 @@
use crate::services::sort::SortController;
use lib_infra::future::BoxResultFuture;
use async_trait::async_trait;
use lib_infra::priority_task::{TaskContent, TaskHandler};
use std::sync::Arc;
use tokio::sync::RwLock;
@ -19,6 +20,7 @@ impl SortTaskHandler {
}
}
#[async_trait]
impl TaskHandler for SortTaskHandler {
fn handler_id(&self) -> &str {
&self.handler_id
@ -28,18 +30,16 @@ impl TaskHandler for SortTaskHandler {
"SortTaskHandler"
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), anyhow::Error> {
async fn run(&self, content: TaskContent) -> Result<(), anyhow::Error> {
let sort_controller = self.sort_controller.clone();
Box::pin(async move {
if let TaskContent::Text(predicate) = content {
sort_controller
.write()
.await
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
})
if let TaskContent::Text(predicate) = content {
sort_controller
.write()
.await
.process(&predicate)
.await
.map_err(anyhow::Error::from)?;
}
Ok(())
}
}

View File

@ -2,11 +2,11 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
use crate::future::BoxResultFuture;
use crate::priority_task::queue::TaskQueue;
use crate::priority_task::store::TaskStore;
use crate::priority_task::{Task, TaskContent, TaskId, TaskState};
use anyhow::Error;
use async_trait::async_trait;
use tokio::sync::{watch, RwLock};
use tokio::time::interval;
@ -160,6 +160,7 @@ impl TaskRunner {
}
}
#[async_trait]
pub trait TaskHandler: Send + Sync + 'static {
fn handler_id(&self) -> &str;
@ -167,9 +168,10 @@ pub trait TaskHandler: Send + Sync + 'static {
""
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), Error>;
async fn run(&self, content: TaskContent) -> Result<(), Error>;
}
#[async_trait]
impl<T> TaskHandler for Box<T>
where
T: TaskHandler,
@ -182,11 +184,12 @@ where
(**self).handler_name()
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), Error> {
(**self).run(content)
async fn run(&self, content: TaskContent) -> Result<(), Error> {
(**self).run(content).await
}
}
#[async_trait]
impl<T> TaskHandler for Arc<T>
where
T: TaskHandler,
@ -199,7 +202,7 @@ where
(**self).handler_name()
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), Error> {
(**self).run(content)
async fn run(&self, content: TaskContent) -> Result<(), Error> {
(**self).run(content).await
}
}

View File

@ -170,22 +170,21 @@ impl RefCountValue for MockBlobTaskHandler {
async fn did_remove(&self) {}
}
#[async_trait]
impl TaskHandler for MockBlobTaskHandler {
fn handler_id(&self) -> &str {
"2"
}
fn run(&self, content: TaskContent) -> BoxResultFuture<(), Error> {
Box::pin(async move {
match content {
TaskContent::Text(_) => panic!("Only support blob"),
TaskContent::Blob(bytes) => {
let _msg = String::from_utf8(bytes).unwrap();
tokio::time::sleep(Duration::from_millis(20)).await;
},
}
Ok(())
})
async fn run(&self, content: TaskContent) -> Result<(), Error> {
match content {
TaskContent::Text(_) => panic!("Only support blob"),
TaskContent::Blob(bytes) => {
let _msg = String::from_utf8(bytes).unwrap();
tokio::time::sleep(Duration::from_millis(20)).await;
},
}
Ok(())
}
}