chore: remove future result (#5960)

* chore: remove future result

* chore: fix test
This commit is contained in:
Nathan.fooo 2024-08-14 15:50:21 +08:00 committed by GitHub
parent 4b24b41dd4
commit 6d496b2088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 145 additions and 222 deletions

View File

@ -20,34 +20,34 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
tauri-build-self-hosted: # tauri-build-self-hosted:
if: github.event.pull_request.head.repo.full_name == github.repository # if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: self-hosted # runs-on: self-hosted
#
steps: # steps:
- uses: actions/checkout@v4 # - uses: actions/checkout@v4
- name: install frontend dependencies # - name: install frontend dependencies
working-directory: frontend/appflowy_web_app # working-directory: frontend/appflowy_web_app
run: | # run: |
mkdir dist # mkdir dist
pnpm install # pnpm install
cd src-tauri && cargo build # cd src-tauri && cargo build
#
- name: test and lint # - name: test and lint
working-directory: frontend/appflowy_web_app # working-directory: frontend/appflowy_web_app
run: | # run: |
pnpm run lint:tauri # pnpm run lint:tauri
#
- uses: tauri-apps/tauri-action@v0 # - uses: tauri-apps/tauri-action@v0
env: # env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: # with:
tauriScript: pnpm tauri # tauriScript: pnpm tauri
projectPath: frontend/appflowy_web_app # projectPath: frontend/appflowy_web_app
args: "--debug" # args: "--debug"
tauri-build-ubuntu: tauri-build-ubuntu:
if: github.event.pull_request.head.repo.full_name != github.repository #if: github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:

View File

@ -122,7 +122,7 @@ mod test {
#[tokio::test] #[tokio::test]
async fn retrieve_gpt4all_model_test() { async fn retrieve_gpt4all_model_test() {
for url in [ for url in [
"https://gpt4all.io/models/gguf/all-MiniLM-L6-v2-f16.gguf", // "https://gpt4all.io/models/gguf/all-MiniLM-L6-v2-f16.gguf",
"https://huggingface.co/second-state/All-MiniLM-L6-v2-Embedding-GGUF/resolve/main/all-MiniLM-L6-v2-Q3_K_L.gguf?download=true", "https://huggingface.co/second-state/All-MiniLM-L6-v2-Embedding-GGUF/resolve/main/all-MiniLM-L6-v2-Q3_K_L.gguf?download=true",
// "https://huggingface.co/MaziyarPanahi/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3.Q4_K_M.gguf?download=true", // "https://huggingface.co/MaziyarPanahi/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3.Q4_K_M.gguf?download=true",
] { ] {
@ -134,7 +134,7 @@ mod test {
let cancel_token = CancellationToken::new(); let cancel_token = CancellationToken::new();
let token = cancel_token.clone(); let token = cancel_token.clone();
tokio::spawn(async move { tokio::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(30)).await; tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;
token.cancel(); token.cancel();
}); });

View File

@ -7,7 +7,7 @@ use flowy_document::manager::DocumentManager;
use flowy_document::reminder::{DocumentReminder, DocumentReminderAction}; use flowy_document::reminder::{DocumentReminder, DocumentReminderAction};
use flowy_folder_pub::cloud::Error; use flowy_folder_pub::cloud::Error;
use flowy_user::services::collab_interact::CollabInteract; use flowy_user::services::collab_interact::CollabInteract;
use lib_infra::future::FutureResult; use lib_infra::async_trait::async_trait;
pub struct CollabInteractImpl { pub struct CollabInteractImpl {
#[allow(dead_code)] #[allow(dead_code)]
@ -16,50 +16,42 @@ pub struct CollabInteractImpl {
pub(crate) document_manager: Weak<DocumentManager>, pub(crate) document_manager: Weak<DocumentManager>,
} }
#[async_trait]
impl CollabInteract for CollabInteractImpl { impl CollabInteract for CollabInteractImpl {
fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> { async fn add_reminder(&self, reminder: Reminder) -> Result<(), Error> {
let cloned_document_manager = self.document_manager.clone(); if let Some(document_manager) = self.document_manager.upgrade() {
FutureResult::new(async move { match DocumentReminder::try_from(reminder) {
if let Some(document_manager) = cloned_document_manager.upgrade() { Ok(reminder) => {
match DocumentReminder::try_from(reminder) { document_manager
Ok(reminder) => { .handle_reminder_action(DocumentReminderAction::Add { reminder })
document_manager .await;
.handle_reminder_action(DocumentReminderAction::Add { reminder }) },
.await; Err(e) => tracing::error!("Failed to add reminder: {:?}", e),
},
Err(e) => tracing::error!("Failed to add reminder: {:?}", e),
}
} }
Ok(()) }
}) Ok(())
} }
fn remove_reminder(&self, reminder_id: &str) -> FutureResult<(), Error> { async fn remove_reminder(&self, reminder_id: &str) -> Result<(), Error> {
let reminder_id = reminder_id.to_string(); let reminder_id = reminder_id.to_string();
let cloned_document_manager = self.document_manager.clone(); if let Some(document_manager) = self.document_manager.upgrade() {
FutureResult::new(async move { let action = DocumentReminderAction::Remove { reminder_id };
if let Some(document_manager) = cloned_document_manager.upgrade() { document_manager.handle_reminder_action(action).await;
let action = DocumentReminderAction::Remove { reminder_id }; }
document_manager.handle_reminder_action(action).await; Ok(())
}
Ok(())
})
} }
fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> { async fn update_reminder(&self, reminder: Reminder) -> Result<(), Error> {
let cloned_document_manager = self.document_manager.clone(); if let Some(document_manager) = self.document_manager.upgrade() {
FutureResult::new(async move { match DocumentReminder::try_from(reminder) {
if let Some(document_manager) = cloned_document_manager.upgrade() { Ok(reminder) => {
match DocumentReminder::try_from(reminder) { document_manager
Ok(reminder) => { .handle_reminder_action(DocumentReminderAction::Update { reminder })
document_manager .await;
.handle_reminder_action(DocumentReminderAction::Update { reminder }) },
.await; Err(e) => tracing::error!("Failed to update reminder: {:?}", e),
},
Err(e) => tracing::error!("Failed to update reminder: {:?}", e),
}
} }
Ok(()) }
}) Ok(())
} }
} }

View File

@ -48,40 +48,39 @@ use crate::integrate::server::{Server, ServerProvider};
#[async_trait] #[async_trait]
impl StorageCloudService for ServerProvider { impl StorageCloudService for ServerProvider {
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError> { async fn get_object_url(&self, object_id: ObjectIdentity) -> Result<String, FlowyError> {
let server = self.get_server(); let storage = self
FutureResult::new(async move { .get_server()?
let storage = server?.file_storage().ok_or(FlowyError::internal())?; .file_storage()
storage.get_object_url(object_id).await .ok_or(FlowyError::internal())?;
}) storage.get_object_url(object_id).await
} }
fn put_object(&self, url: String, val: ObjectValue) -> FutureResult<(), FlowyError> { async fn put_object(&self, url: String, val: ObjectValue) -> Result<(), FlowyError> {
let server = self.get_server(); let storage = self
FutureResult::new(async move { .get_server()?
let storage = server?.file_storage().ok_or(FlowyError::internal())?; .file_storage()
storage.put_object(url, val).await .ok_or(FlowyError::internal())?;
}) storage.put_object(url, val).await
} }
fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError> { async fn delete_object(&self, url: &str) -> Result<(), FlowyError> {
let server = self.get_server(); let storage = self
let url = url.to_string(); .get_server()?
FutureResult::new(async move { .file_storage()
let storage = server?.file_storage().ok_or(FlowyError::internal())?; .ok_or(FlowyError::internal())?;
storage.delete_object(&url).await storage.delete_object(url).await
})
} }
fn get_object(&self, url: String) -> FutureResult<ObjectValue, FlowyError> { async fn get_object(&self, url: String) -> Result<ObjectValue, FlowyError> {
let server = self.get_server(); let storage = self
FutureResult::new(async move { .get_server()?
let storage = server?.file_storage().ok_or(FlowyError::internal())?; .file_storage()
storage.get_object(url).await .ok_or(FlowyError::internal())?;
}) storage.get_object(url).await
} }
fn get_object_url_v1( async fn get_object_url_v1(
&self, &self,
workspace_id: &str, workspace_id: &str,
parent_dir: &str, parent_dir: &str,
@ -89,7 +88,9 @@ impl StorageCloudService for ServerProvider {
) -> FlowyResult<String> { ) -> FlowyResult<String> {
let server = self.get_server()?; let server = self.get_server()?;
let storage = server.file_storage().ok_or(FlowyError::internal())?; let storage = server.file_storage().ok_or(FlowyError::internal())?;
storage.get_object_url_v1(workspace_id, parent_dir, file_id) storage
.get_object_url_v1(workspace_id, parent_dir, file_id)
.await
} }
async fn create_upload( async fn create_upload(

View File

@ -1,12 +1,13 @@
use crate::entities::{PublishInfoResponse, PublishPayload};
pub use anyhow::Error; pub use anyhow::Error;
use collab_entity::CollabType; use collab_entity::CollabType;
pub use collab_folder::{Folder, FolderData, Workspace}; pub use collab_folder::{Folder, FolderData, Workspace};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use uuid::Uuid; use uuid::Uuid;
use crate::entities::{PublishInfoResponse, PublishPayload};
use lib_infra::future::FutureResult;
/// [FolderCloudService] represents the cloud service for folder. /// [FolderCloudService] represents the cloud service for folder.
#[async_trait]
pub trait FolderCloudService: Send + Sync + 'static { pub trait FolderCloudService: Send + Sync + 'static {
/// Creates a new workspace for the user. /// Creates a new workspace for the user.
/// Returns error if the cloud service doesn't support multiple workspaces /// Returns error if the cloud service doesn't support multiple workspaces

View File

@ -1,11 +1,9 @@
use crate::af_cloud::AFServer;
use client_api::entity::{CompleteUploadRequest, CreateUploadRequest}; use client_api::entity::{CompleteUploadRequest, CreateUploadRequest};
use flowy_error::{FlowyError, FlowyResult}; use flowy_error::FlowyError;
use flowy_storage_pub::cloud::{ObjectIdentity, ObjectValue, StorageCloudService}; use flowy_storage_pub::cloud::{ObjectIdentity, ObjectValue, StorageCloudService};
use flowy_storage_pub::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse}; use flowy_storage_pub::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse};
use lib_infra::async_trait::async_trait; use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use crate::af_cloud::AFServer;
pub struct AFCloudFileStorageServiceImpl<T>(pub T); pub struct AFCloudFileStorageServiceImpl<T>(pub T);
@ -20,56 +18,44 @@ impl<T> StorageCloudService for AFCloudFileStorageServiceImpl<T>
where where
T: AFServer, T: AFServer,
{ {
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError> { async fn get_object_url(&self, object_id: ObjectIdentity) -> Result<String, FlowyError> {
let try_get_client = self.0.try_get_client(); let file_name = format!("{}.{}", object_id.file_id, object_id.ext);
FutureResult::new(async move { let url = self
let file_name = format!("{}.{}", object_id.file_id, object_id.ext); .0
let client = try_get_client?; .try_get_client()?
let url = client.get_blob_url(&object_id.workspace_id, &file_name); .get_blob_url(&object_id.workspace_id, &file_name);
Ok(url) Ok(url)
}
async fn put_object(&self, url: String, file: ObjectValue) -> Result<(), FlowyError> {
let client = self.0.try_get_client()?;
client.put_blob(&url, file.raw, &file.mime).await?;
Ok(())
}
async fn delete_object(&self, url: &str) -> Result<(), FlowyError> {
self.0.try_get_client()?.delete_blob(url).await?;
Ok(())
}
async fn get_object(&self, url: String) -> Result<ObjectValue, FlowyError> {
let (mime, raw) = self.0.try_get_client()?.get_blob(&url).await?;
Ok(ObjectValue {
raw: raw.into(),
mime,
}) })
} }
fn put_object(&self, url: String, file: ObjectValue) -> FutureResult<(), FlowyError> { async fn get_object_url_v1(
let try_get_client = self.0.try_get_client();
let file = file.clone();
FutureResult::new(async move {
let client = try_get_client?;
client.put_blob(&url, file.raw, &file.mime).await?;
Ok(())
})
}
fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError> {
let url = url.to_string();
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
client.delete_blob(&url).await?;
Ok(())
})
}
fn get_object(&self, url: String) -> FutureResult<ObjectValue, FlowyError> {
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let client = try_get_client?;
let (mime, raw) = client.get_blob(&url).await?;
Ok(ObjectValue {
raw: raw.into(),
mime,
})
})
}
fn get_object_url_v1(
&self, &self,
workspace_id: &str, workspace_id: &str,
parent_dir: &str, parent_dir: &str,
file_id: &str, file_id: &str,
) -> FlowyResult<String> { ) -> Result<String, FlowyError> {
let client = self.0.try_get_client()?; let url = self
let url = client.get_blob_url_v1(workspace_id, parent_dir, file_id); .0
.try_get_client()?
.get_blob_url_v1(workspace_id, parent_dir, file_id);
Ok(url) Ok(url)
} }

View File

@ -1,7 +1,5 @@
pub use entities::*; pub use entities::*;
pub use plan::*;
mod builder; mod builder;
pub mod core; pub mod core;
mod entities; mod entities;
pub mod plan;

View File

@ -1,42 +0,0 @@
use std::sync::Weak;
use parking_lot::RwLock;
use flowy_error::FlowyError;
use flowy_storage_pub::cloud::{FileStoragePlan, StorageObject};
use lib_infra::future::FutureResult;
use crate::supabase::api::RESTfulPostgresServer;
#[derive(Default)]
pub struct FileStoragePlanImpl {
#[allow(dead_code)]
uid: Weak<RwLock<Option<i64>>>,
#[allow(dead_code)]
postgrest: Option<Weak<RESTfulPostgresServer>>,
}
impl FileStoragePlanImpl {
pub fn new(
uid: Weak<RwLock<Option<i64>>>,
postgrest: Option<Weak<RESTfulPostgresServer>>,
) -> Self {
Self { uid, postgrest }
}
}
impl FileStoragePlan for FileStoragePlanImpl {
fn storage_size(&self) -> FutureResult<u64, FlowyError> {
// 1 GB
FutureResult::new(async { Ok(1024 * 1024 * 1024) })
}
fn maximum_file_size(&self) -> FutureResult<u64, FlowyError> {
// 5 MB
FutureResult::new(async { Ok(5 * 1024 * 1024) })
}
fn check_upload_object(&self, _object: &StorageObject) -> FutureResult<(), FlowyError> {
FutureResult::new(async { Ok(()) })
}
}

View File

@ -2,7 +2,6 @@ use crate::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartRespo
use async_trait::async_trait; use async_trait::async_trait;
use bytes::Bytes; use bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult}; use flowy_error::{FlowyError, FlowyResult};
use lib_infra::future::FutureResult;
use mime::Mime; use mime::Mime;
#[async_trait] #[async_trait]
@ -15,7 +14,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns /// # Returns
/// - `Ok()` /// - `Ok()`
/// - `Err(Error)`: An error occurred during the operation. /// - `Err(Error)`: An error occurred during the operation.
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError>; async fn get_object_url(&self, object_id: ObjectIdentity) -> Result<String, FlowyError>;
/// Creates a new storage object. /// Creates a new storage object.
/// ///
@ -25,7 +24,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns /// # Returns
/// - `Ok()` /// - `Ok()`
/// - `Err(Error)`: An error occurred during the operation. /// - `Err(Error)`: An error occurred during the operation.
fn put_object(&self, url: String, object_value: ObjectValue) -> FutureResult<(), FlowyError>; async fn put_object(&self, url: String, object_value: ObjectValue) -> Result<(), FlowyError>;
/// Deletes a storage object by its URL. /// Deletes a storage object by its URL.
/// ///
@ -35,7 +34,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns /// # Returns
/// - `Ok()` /// - `Ok()`
/// - `Err(Error)`: An error occurred during the operation. /// - `Err(Error)`: An error occurred during the operation.
fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError>; async fn delete_object(&self, url: &str) -> Result<(), FlowyError>;
/// Fetches a storage object by its URL. /// Fetches a storage object by its URL.
/// ///
@ -45,8 +44,8 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns /// # Returns
/// - `Ok(File)`: The returned file object. /// - `Ok(File)`: The returned file object.
/// - `Err(Error)`: An error occurred during the operation. /// - `Err(Error)`: An error occurred during the operation.
fn get_object(&self, url: String) -> FutureResult<ObjectValue, FlowyError>; async fn get_object(&self, url: String) -> Result<ObjectValue, FlowyError>;
fn get_object_url_v1( async fn get_object_url_v1(
&self, &self,
workspace_id: &str, workspace_id: &str,
parent_dir: &str, parent_dir: &str,
@ -81,13 +80,6 @@ pub trait StorageCloudService: Send + Sync {
) -> Result<(), FlowyError>; ) -> Result<(), FlowyError>;
} }
pub trait FileStoragePlan: Send + Sync + 'static {
fn storage_size(&self) -> FutureResult<u64, FlowyError>;
fn maximum_file_size(&self) -> FutureResult<u64, FlowyError>;
fn check_upload_object(&self, object: &StorageObject) -> FutureResult<(), FlowyError>;
}
pub struct ObjectIdentity { pub struct ObjectIdentity {
pub workspace_id: String, pub workspace_id: String,
pub file_id: String, pub file_id: String,

View File

@ -263,11 +263,10 @@ impl StorageService for StorageServiceImpl {
let conn = self let conn = self
.user_service .user_service
.sqlite_connection(self.user_service.user_id()?)?; .sqlite_connection(self.user_service.user_id()?)?;
let url = self.cloud_service.get_object_url_v1( let url = self
&record.workspace_id, .cloud_service
&record.parent_dir, .get_object_url_v1(&record.workspace_id, &record.parent_dir, &record.file_id)
&record.file_id, .await?;
)?;
let file_id = record.file_id.clone(); let file_id = record.file_id.clone();
match insert_upload_file(conn, &record) { match insert_upload_file(conn, &record) {
Ok(_) => { Ok(_) => {

View File

@ -1,25 +1,21 @@
use anyhow::Error; use anyhow::Error;
use collab_entity::reminder::Reminder; use collab_entity::reminder::Reminder;
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult; #[async_trait]
pub trait CollabInteract: Send + Sync + 'static { pub trait CollabInteract: Send + Sync + 'static {
fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>; async fn add_reminder(&self, _reminder: Reminder) -> Result<(), Error> {
fn remove_reminder(&self, reminder_id: &str) -> FutureResult<(), Error>; Ok(())
fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>; }
async fn remove_reminder(&self, _reminder_id: &str) -> Result<(), Error> {
Ok(())
}
async fn update_reminder(&self, _reminder: Reminder) -> Result<(), Error> {
Ok(())
}
} }
pub struct DefaultCollabInteract; pub struct DefaultCollabInteract;
impl CollabInteract for DefaultCollabInteract {
fn add_reminder(&self, _reminder: Reminder) -> FutureResult<(), Error> {
FutureResult::new(async { Ok(()) })
}
fn remove_reminder(&self, _reminder_id: &str) -> FutureResult<(), Error> { #[async_trait]
FutureResult::new(async { Ok(()) }) impl CollabInteract for DefaultCollabInteract {}
}
fn update_reminder(&self, _reminder: Reminder) -> FutureResult<(), Error> {
FutureResult::new(async { Ok(()) })
}
}