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
jobs:
tauri-build-self-hosted:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: install frontend dependencies
working-directory: frontend/appflowy_web_app
run: |
mkdir dist
pnpm install
cd src-tauri && cargo build
- name: test and lint
working-directory: frontend/appflowy_web_app
run: |
pnpm run lint:tauri
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tauriScript: pnpm tauri
projectPath: frontend/appflowy_web_app
args: "--debug"
# tauri-build-self-hosted:
# if: github.event.pull_request.head.repo.full_name == github.repository
# runs-on: self-hosted
#
# steps:
# - uses: actions/checkout@v4
# - name: install frontend dependencies
# working-directory: frontend/appflowy_web_app
# run: |
# mkdir dist
# pnpm install
# cd src-tauri && cargo build
#
# - name: test and lint
# working-directory: frontend/appflowy_web_app
# run: |
# pnpm run lint:tauri
#
# - uses: tauri-apps/tauri-action@v0
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tauriScript: pnpm tauri
# projectPath: frontend/appflowy_web_app
# args: "--debug"
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
steps:

View File

@ -122,7 +122,7 @@ mod test {
#[tokio::test]
async fn retrieve_gpt4all_model_test() {
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/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 token = cancel_token.clone();
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();
});

View File

@ -7,7 +7,7 @@ use flowy_document::manager::DocumentManager;
use flowy_document::reminder::{DocumentReminder, DocumentReminderAction};
use flowy_folder_pub::cloud::Error;
use flowy_user::services::collab_interact::CollabInteract;
use lib_infra::future::FutureResult;
use lib_infra::async_trait::async_trait;
pub struct CollabInteractImpl {
#[allow(dead_code)]
@ -16,50 +16,42 @@ pub struct CollabInteractImpl {
pub(crate) document_manager: Weak<DocumentManager>,
}
#[async_trait]
impl CollabInteract for CollabInteractImpl {
fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> {
let cloned_document_manager = self.document_manager.clone();
FutureResult::new(async move {
if let Some(document_manager) = cloned_document_manager.upgrade() {
match DocumentReminder::try_from(reminder) {
Ok(reminder) => {
document_manager
.handle_reminder_action(DocumentReminderAction::Add { reminder })
.await;
},
Err(e) => tracing::error!("Failed to add reminder: {:?}", e),
}
async fn add_reminder(&self, reminder: Reminder) -> Result<(), Error> {
if let Some(document_manager) = self.document_manager.upgrade() {
match DocumentReminder::try_from(reminder) {
Ok(reminder) => {
document_manager
.handle_reminder_action(DocumentReminderAction::Add { reminder })
.await;
},
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 cloned_document_manager = self.document_manager.clone();
FutureResult::new(async move {
if let Some(document_manager) = cloned_document_manager.upgrade() {
let action = DocumentReminderAction::Remove { reminder_id };
document_manager.handle_reminder_action(action).await;
}
Ok(())
})
if let Some(document_manager) = self.document_manager.upgrade() {
let action = DocumentReminderAction::Remove { reminder_id };
document_manager.handle_reminder_action(action).await;
}
Ok(())
}
fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> {
let cloned_document_manager = self.document_manager.clone();
FutureResult::new(async move {
if let Some(document_manager) = cloned_document_manager.upgrade() {
match DocumentReminder::try_from(reminder) {
Ok(reminder) => {
document_manager
.handle_reminder_action(DocumentReminderAction::Update { reminder })
.await;
},
Err(e) => tracing::error!("Failed to update reminder: {:?}", e),
}
async fn update_reminder(&self, reminder: Reminder) -> Result<(), Error> {
if let Some(document_manager) = self.document_manager.upgrade() {
match DocumentReminder::try_from(reminder) {
Ok(reminder) => {
document_manager
.handle_reminder_action(DocumentReminderAction::Update { reminder })
.await;
},
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]
impl StorageCloudService for ServerProvider {
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage.get_object_url(object_id).await
})
async fn get_object_url(&self, object_id: ObjectIdentity) -> Result<String, FlowyError> {
let storage = self
.get_server()?
.file_storage()
.ok_or(FlowyError::internal())?;
storage.get_object_url(object_id).await
}
fn put_object(&self, url: String, val: ObjectValue) -> FutureResult<(), FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage.put_object(url, val).await
})
async fn put_object(&self, url: String, val: ObjectValue) -> Result<(), FlowyError> {
let storage = self
.get_server()?
.file_storage()
.ok_or(FlowyError::internal())?;
storage.put_object(url, val).await
}
fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError> {
let server = self.get_server();
let url = url.to_string();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage.delete_object(&url).await
})
async fn delete_object(&self, url: &str) -> Result<(), FlowyError> {
let storage = self
.get_server()?
.file_storage()
.ok_or(FlowyError::internal())?;
storage.delete_object(url).await
}
fn get_object(&self, url: String) -> FutureResult<ObjectValue, FlowyError> {
let server = self.get_server();
FutureResult::new(async move {
let storage = server?.file_storage().ok_or(FlowyError::internal())?;
storage.get_object(url).await
})
async fn get_object(&self, url: String) -> Result<ObjectValue, FlowyError> {
let storage = self
.get_server()?
.file_storage()
.ok_or(FlowyError::internal())?;
storage.get_object(url).await
}
fn get_object_url_v1(
async fn get_object_url_v1(
&self,
workspace_id: &str,
parent_dir: &str,
@ -89,7 +88,9 @@ impl StorageCloudService for ServerProvider {
) -> FlowyResult<String> {
let server = self.get_server()?;
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(

View File

@ -1,12 +1,13 @@
use crate::entities::{PublishInfoResponse, PublishPayload};
pub use anyhow::Error;
use collab_entity::CollabType;
pub use collab_folder::{Folder, FolderData, Workspace};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use uuid::Uuid;
use crate::entities::{PublishInfoResponse, PublishPayload};
use lib_infra::future::FutureResult;
/// [FolderCloudService] represents the cloud service for folder.
#[async_trait]
pub trait FolderCloudService: Send + Sync + 'static {
/// Creates a new workspace for the user.
/// 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 flowy_error::{FlowyError, FlowyResult};
use flowy_error::FlowyError;
use flowy_storage_pub::cloud::{ObjectIdentity, ObjectValue, StorageCloudService};
use flowy_storage_pub::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse};
use lib_infra::async_trait::async_trait;
use lib_infra::future::FutureResult;
use crate::af_cloud::AFServer;
pub struct AFCloudFileStorageServiceImpl<T>(pub T);
@ -20,56 +18,44 @@ impl<T> StorageCloudService for AFCloudFileStorageServiceImpl<T>
where
T: AFServer,
{
fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult<String, FlowyError> {
let try_get_client = self.0.try_get_client();
FutureResult::new(async move {
let file_name = format!("{}.{}", object_id.file_id, object_id.ext);
let client = try_get_client?;
let url = client.get_blob_url(&object_id.workspace_id, &file_name);
Ok(url)
async fn get_object_url(&self, object_id: ObjectIdentity) -> Result<String, FlowyError> {
let file_name = format!("{}.{}", object_id.file_id, object_id.ext);
let url = self
.0
.try_get_client()?
.get_blob_url(&object_id.workspace_id, &file_name);
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> {
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(
async fn get_object_url_v1(
&self,
workspace_id: &str,
parent_dir: &str,
file_id: &str,
) -> FlowyResult<String> {
let client = self.0.try_get_client()?;
let url = client.get_blob_url_v1(workspace_id, parent_dir, file_id);
) -> Result<String, FlowyError> {
let url = self
.0
.try_get_client()?
.get_blob_url_v1(workspace_id, parent_dir, file_id);
Ok(url)
}

View File

@ -1,7 +1,5 @@
pub use entities::*;
pub use plan::*;
mod builder;
pub mod core;
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 bytes::Bytes;
use flowy_error::{FlowyError, FlowyResult};
use lib_infra::future::FutureResult;
use mime::Mime;
#[async_trait]
@ -15,7 +14,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns
/// - `Ok()`
/// - `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.
///
@ -25,7 +24,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns
/// - `Ok()`
/// - `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.
///
@ -35,7 +34,7 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns
/// - `Ok()`
/// - `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.
///
@ -45,8 +44,8 @@ pub trait StorageCloudService: Send + Sync {
/// # Returns
/// - `Ok(File)`: The returned file object.
/// - `Err(Error)`: An error occurred during the operation.
fn get_object(&self, url: String) -> FutureResult<ObjectValue, FlowyError>;
fn get_object_url_v1(
async fn get_object(&self, url: String) -> Result<ObjectValue, FlowyError>;
async fn get_object_url_v1(
&self,
workspace_id: &str,
parent_dir: &str,
@ -81,13 +80,6 @@ pub trait StorageCloudService: Send + Sync {
) -> 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 workspace_id: String,
pub file_id: String,

View File

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

View File

@ -1,25 +1,21 @@
use anyhow::Error;
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 {
fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>;
fn remove_reminder(&self, reminder_id: &str) -> FutureResult<(), Error>;
fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>;
async fn add_reminder(&self, _reminder: Reminder) -> Result<(), Error> {
Ok(())
}
async fn remove_reminder(&self, _reminder_id: &str) -> Result<(), Error> {
Ok(())
}
async fn update_reminder(&self, _reminder: Reminder) -> Result<(), Error> {
Ok(())
}
}
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> {
FutureResult::new(async { Ok(()) })
}
fn update_reminder(&self, _reminder: Reminder) -> FutureResult<(), Error> {
FutureResult::new(async { Ok(()) })
}
}
#[async_trait]
impl CollabInteract for DefaultCollabInteract {}