Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Jun 23, 2024
1 parent 2a82837 commit 6236fed
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::util::receive_with_timeout;

use event_integration_test::user_event::user_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_chat::entities::{ChatMessageListPB, CompletionTypePB};
use flowy_chat::notification::ChatNotification;
use flowy_chat_pub::cloud::ChatMessageType;
use flowy_chat::entities::{CompletionTypePB};


use std::time::Duration;

#[tokio::test]
Expand All @@ -12,8 +12,8 @@ async fn af_cloud_complete_text_test() {
let test = EventIntegrationTest::new().await;
test.af_cloud_sign_up().await;

let workspace_id = test.get_current_workspace().await.id;
let task = test
let _workspace_id = test.get_current_workspace().await.id;
let _task = test
.complete_text("hello world", CompletionTypePB::MakeLonger)
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ async fn af_cloud_upload_file_test() {
.unwrap();

while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::Finish {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::Finish {
break;
}
}

Expand All @@ -54,10 +52,8 @@ async fn af_cloud_upload_big_file_test() {

let mut rx = test.storage_manager.subscribe_upload_result();
while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::InProgress {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::InProgress {
break;
}
}

Expand All @@ -71,10 +67,8 @@ async fn af_cloud_upload_big_file_test() {
let test = EventIntegrationTest::new_with_config(config).await;
let mut rx = test.storage_manager.subscribe_upload_result();
while let Ok(result) = rx.recv().await {
if result.file_id == created_upload.file_id {
if result.status == UploadStatus::Finish {
break;
}
if result.file_id == created_upload.file_id && result.status == UploadStatus::Finish {
break;
}
}

Expand All @@ -101,7 +95,7 @@ async fn af_cloud_upload_6_files_test() {
let mut rx = test.storage_manager.subscribe_upload_result();

let mut created_uploads = vec![];
for file_size in vec![1, 2, 5, 8, 12, 20] {
for file_size in [1, 2, 5, 8, 12, 20] {
let file_path = generate_file_with_bytes_len(file_size * 1024 * 1024)
.await
.0;
Expand Down
18 changes: 9 additions & 9 deletions frontend/rust-lib/flowy-chat/src/tools.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::chat_manager::ChatUserService;
use crate::entities::{CompleteTextPB, CompleteTextTaskPB, CompletionTypePB};
use allo_isolate::Isolate;
use bytes::Bytes;

use dashmap::DashMap;
use flowy_chat_pub::cloud::{ChatCloudService, CompletionType, StreamComplete};
use flowy_chat_pub::cloud::{ChatCloudService, CompletionType};
use flowy_error::{FlowyError, FlowyResult};
use futures::future::err;

use futures::{SinkExt, StreamExt};
use lib_infra::isolate_stream::IsolateSink;
use std::sync::atomic::AtomicBool;

use std::sync::{Arc, Weak};
use tokio::select;
use tracing::{error, trace};
Expand Down Expand Up @@ -38,7 +38,7 @@ impl AITools {
let workspace_id = self
.user_service
.upgrade()
.ok_or_else(|| FlowyError::internal())?
.ok_or_else(FlowyError::internal)?
.workspace_id()?;
let (tx, rx) = tokio::sync::mpsc::channel(1);
let task = ToolTask::new(workspace_id, complete, self.cloud_service.clone(), rx);
Expand All @@ -51,7 +51,7 @@ impl AITools {

pub async fn cancel_complete_task(&self, task_id: &str) {
if let Some(entry) = self.tasks.remove(task_id) {
let _ = entry.1.send(());
let _ = entry.1.send(()).await;
}
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl ToolTask {
CompletionTypePB::MakeLonger => CompletionType::MakeLonger,
CompletionTypePB::ContinueWriting => CompletionType::ContinueWriting,
};
let _ = sink.send(format!("start:",)).await;
let _ = sink.send("start:".to_string()).await;
match cloud_service
.stream_complete(&self.workspace_id, &self.context.text, complete_type)
.await
Expand All @@ -113,7 +113,7 @@ impl ToolTask {
},
Some(Err(error)) => {
error!("stream error: {}", error);
let _ = sink.send(format!("error:{}", error.to_string())).await;
let _ = sink.send(format!("error:{}", error)).await;
return;
},
None => {
Expand All @@ -126,7 +126,7 @@ impl ToolTask {
},
Err(error) => {
error!("stream complete error: {}", error);
let _ = sink.send(format!("error:{}", error.to_string())).await;
let _ = sink.send(format!("error:{}", error)).await;
},
}
},
Expand Down
29 changes: 15 additions & 14 deletions frontend/rust-lib/flowy-storage/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ impl StorageService for StorageServiceImpl {
// When resuming an upload, check if the upload_id is empty.
// If the upload_id is empty, the upload has likely not been created yet.
// If the upload_id is not empty, verify which parts have already been uploaded.
select_upload_file(conn, &workspace_id, &parent_dir, &file_id)?.and_then(|record| {
select_upload_file(conn, workspace_id, parent_dir, file_id)?.map(|record| {
if record.upload_id.is_empty() {
Some((record, vec![]))
(record, vec![])
} else {
let parts = select_upload_parts(conn, &record.upload_id).unwrap_or_default();
Some((record, parts))
(record, parts)
}
}),
)
Expand Down Expand Up @@ -358,7 +358,7 @@ async fn create_upload_record(
let content_type = mime_guess::from_path(&local_file_path)
.first_or_octet_stream()
.to_string();
let file_id = format!("{}.{}", fxhash::hash(&chunked_bytes.data).to_string(), ext);
let file_id = format!("{}.{}", fxhash::hash(&chunked_bytes.data), ext);
let record = UploadFileTable {
workspace_id,
file_id,
Expand Down Expand Up @@ -430,10 +430,10 @@ async fn start_upload(
upload_file.file_id,
chunked_bytes.iter().count()
);
let mut iter = chunked_bytes.iter().enumerate();
let iter = chunked_bytes.iter().enumerate();
let mut completed_parts = Vec::new();

while let Some((index, chunk_bytes)) = iter.next() {
for (index, chunk_bytes) in iter {
let part_number = index as i32 + 1;
trace!(
"[File] {} uploading part: {}, len:{}KB",
Expand All @@ -443,8 +443,8 @@ async fn start_upload(
);
// start uploading parts
match upload_part(
&cloud_service,
&user_service,
cloud_service,
user_service,
&upload_file.workspace_id,
&upload_file.parent_dir,
&upload_file.upload_id,
Expand Down Expand Up @@ -476,8 +476,8 @@ async fn start_upload(

// mark it as completed
complete_upload(
&cloud_service,
&user_service,
cloud_service,
user_service,
temp_storage,
&upload_file,
completed_parts,
Expand Down Expand Up @@ -540,6 +540,7 @@ async fn resume_upload(
Ok(())
}

#[allow(clippy::too_many_arguments)]
#[instrument(level = "debug", skip_all)]
async fn upload_part(
cloud_service: &Arc<dyn StorageCloudService>,
Expand All @@ -553,10 +554,10 @@ async fn upload_part(
) -> Result<UploadPartResponse, FlowyError> {
let resp = cloud_service
.upload_part(
&workspace_id,
&parent_dir,
&upload_id,
&file_id,
workspace_id,
parent_dir,
upload_id,
file_id,
part_number,
body,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::PathBuf;
use std::time::Duration;

pub fn test_database() -> (Database, PathBuf) {
let db_path = temp_dir().join(&format!("test-{}.db", generate_random_string(8)));
let db_path = temp_dir().join(format!("test-{}.db", generate_random_string(8)));
(flowy_sqlite::init(&db_path).unwrap(), db_path)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ async fn test_upload_part_test() {

// get all existing parts
let mut conn = db.get_connection().unwrap();
let parts = select_upload_parts(&mut *conn, &upload_id).unwrap();
let parts = select_upload_parts(&mut conn, &upload_id).unwrap();
assert_eq!(parts.len(), 2);
assert_eq!(parts[0].part_num, 1);
assert_eq!(parts[1].part_num, 2);
Expand All @@ -112,7 +112,7 @@ async fn test_upload_part_test() {
delete_upload_file(conn, &upload_id).unwrap();

let mut conn = db.get_connection().unwrap();
let parts = select_upload_parts(&mut *conn, &upload_id).unwrap();
let parts = select_upload_parts(&mut conn, &upload_id).unwrap();
assert!(parts.is_empty())
}

Expand Down Expand Up @@ -165,7 +165,9 @@ pub async fn create_upload_file_record(
let file_id = fxhash::hash(&chunked_bytes.data).to_string();

// Create UploadFileTable record
let upload_file = UploadFileTable {


UploadFileTable {
workspace_id,
file_id,
upload_id,
Expand All @@ -175,7 +177,5 @@ pub async fn create_upload_file_record(
chunk_size: MIN_CHUNK_SIZE as i32,
num_chunk: chunked_bytes.offsets.len() as i32,
created_at: chrono::Utc::now().timestamp(),
};

upload_file
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl UserManager {

pub async fn get_workspace_settings(&self, workspace_id: &str) -> FlowyResult<UseAISettingPB> {
let cloud_service = self.cloud_services.get_user_service()?;
let settings = cloud_service.get_workspace_setting(&workspace_id).await?;
let settings = cloud_service.get_workspace_setting(workspace_id).await?;

let uid = self.user_id()?;
let conn = self.db_connection(uid)?;
Expand Down

0 comments on commit 6236fed

Please sign in to comment.