perf: 使用 itertools 提供的 join,避免 collect 到 Vec 的额外分配 (#652)
This commit is contained in:
@@ -116,10 +116,7 @@ async fn execute_page_update_batch(
|
|||||||
txn: &DatabaseTransaction,
|
txn: &DatabaseTransaction,
|
||||||
pages: impl Iterator<Item = (i32, u32)>,
|
pages: impl Iterator<Item = (i32, u32)>,
|
||||||
) -> Result<(), sea_orm::DbErr> {
|
) -> Result<(), sea_orm::DbErr> {
|
||||||
let values = pages
|
let values = pages.map(|p| format!("({}, {})", p.0, p.1)).join(", ");
|
||||||
.map(|p| format!("({}, {})", p.0, p.1))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ");
|
|
||||||
if values.is_empty() {
|
if values.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use axum::routing::{get, post, put};
|
|||||||
use bili_sync_entity::rule::Rule;
|
use bili_sync_entity::rule::Rule;
|
||||||
use bili_sync_entity::*;
|
use bili_sync_entity::*;
|
||||||
use bili_sync_migration::Expr;
|
use bili_sync_migration::Expr;
|
||||||
|
use itertools::Itertools;
|
||||||
use sea_orm::ActiveValue::Set;
|
use sea_orm::ActiveValue::Set;
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QuerySelect, QueryTrait, TransactionTrait};
|
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 \
|
SET should_download = tempdata.should_download \
|
||||||
FROM tempdata \
|
FROM tempdata \
|
||||||
WHERE video.id = tempdata.id",
|
WHERE video.id = tempdata.id",
|
||||||
chunk
|
chunk.iter().map(|item| format!("({}, {})", item.0, item.1)).join(", ")
|
||||||
.iter()
|
|
||||||
.map(|item| format!("({}, {})", item.0, item.1))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", ")
|
|
||||||
);
|
);
|
||||||
txn.execute_unprepared(&sql).await?;
|
txn.execute_unprepared(&sql).await?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::sync::{Arc, LazyLock};
|
|||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use croner::parser::CronParser;
|
use croner::parser::CronParser;
|
||||||
|
use itertools::Itertools;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
@@ -103,13 +104,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
bail!(
|
bail!(errors.into_iter().map(|e| format!("- {}", e)).join("\n"));
|
||||||
errors
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| format!("- {}", e))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join("\n")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user