From bb1576a0df9fda71beea5c47333fbdc806c8d6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Thu, 19 Feb 2026 19:04:10 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BD=BF=E7=94=A8=20itertools=20?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9A=84=20join=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=20collect=20=E5=88=B0=20Vec=20=E7=9A=84=E9=A2=9D=E5=A4=96?= =?UTF-8?q?=E5=88=86=E9=85=8D=20(#652)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/api/helper.rs | 5 +---- crates/bili_sync/src/api/routes/video_sources/mod.rs | 7 ++----- crates/bili_sync/src/config/current.rs | 9 ++------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/crates/bili_sync/src/api/helper.rs b/crates/bili_sync/src/api/helper.rs index 48f7d1b..296e1c6 100644 --- a/crates/bili_sync/src/api/helper.rs +++ b/crates/bili_sync/src/api/helper.rs @@ -116,10 +116,7 @@ async fn execute_page_update_batch( txn: &DatabaseTransaction, pages: impl Iterator, ) -> Result<(), sea_orm::DbErr> { - let values = pages - .map(|p| format!("({}, {})", p.0, p.1)) - .collect::>() - .join(", "); + let values = pages.map(|p| format!("({}, {})", p.0, p.1)).join(", "); if values.is_empty() { return Ok(()); } diff --git a/crates/bili_sync/src/api/routes/video_sources/mod.rs b/crates/bili_sync/src/api/routes/video_sources/mod.rs index e8b5cf3..4616b83 100644 --- a/crates/bili_sync/src/api/routes/video_sources/mod.rs +++ b/crates/bili_sync/src/api/routes/video_sources/mod.rs @@ -7,6 +7,7 @@ use axum::routing::{get, post, put}; use bili_sync_entity::rule::Rule; use bili_sync_entity::*; use bili_sync_migration::Expr; +use itertools::Itertools; use sea_orm::ActiveValue::Set; use sea_orm::entity::prelude::*; use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QuerySelect, QueryTrait, TransactionTrait}; @@ -347,11 +348,7 @@ pub async fn evaluate_video_source( SET should_download = tempdata.should_download \ FROM tempdata \ WHERE video.id = tempdata.id", - chunk - .iter() - .map(|item| format!("({}, {})", item.0, item.1)) - .collect::>() - .join(", ") + chunk.iter().map(|item| format!("({}, {})", item.0, item.1)).join(", ") ); txn.execute_unprepared(&sql).await?; } diff --git a/crates/bili_sync/src/config/current.rs b/crates/bili_sync/src/config/current.rs index 1824934..01ca01d 100644 --- a/crates/bili_sync/src/config/current.rs +++ b/crates/bili_sync/src/config/current.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, LazyLock}; use anyhow::{Result, bail}; use croner::parser::CronParser; +use itertools::Itertools; use sea_orm::DatabaseConnection; use serde::{Deserialize, Serialize}; use validator::Validate; @@ -103,13 +104,7 @@ impl Config { } }; if !errors.is_empty() { - bail!( - errors - .into_iter() - .map(|e| format!("- {}", e)) - .collect::>() - .join("\n") - ); + bail!(errors.into_iter().map(|e| format!("- {}", e)).join("\n")); } Ok(()) }