mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-08 13:13:49 -05:00
refactor: avoid a clone if extra images are empty
This commit is contained in:
12
src/check.rs
12
src/check.rs
@@ -90,7 +90,9 @@ pub async fn get_updates(
|
|||||||
// Merge references argument with references from config
|
// Merge references argument with references from config
|
||||||
let all_references = match &references {
|
let all_references = match &references {
|
||||||
Some(refs) => {
|
Some(refs) => {
|
||||||
refs.clone().extend_from_slice(&ctx.config.images.extra);
|
if !ctx.config.images.extra.is_empty() {
|
||||||
|
refs.clone().extend_from_slice(&ctx.config.images.extra);
|
||||||
|
}
|
||||||
refs
|
refs
|
||||||
}
|
}
|
||||||
None => &ctx.config.images.extra,
|
None => &ctx.config.images.extra,
|
||||||
@@ -100,7 +102,8 @@ pub async fn get_updates(
|
|||||||
ctx.logger.debug("Retrieving images to be checked");
|
ctx.logger.debug("Retrieving images to be checked");
|
||||||
let mut images = get_images_from_docker_daemon(ctx, references).await;
|
let mut images = get_images_from_docker_daemon(ctx, references).await;
|
||||||
let in_use_images = get_in_use_images(ctx).await;
|
let in_use_images = get_in_use_images(ctx).await;
|
||||||
ctx.logger.debug(format!("Found {} images in use", in_use_images.len()));
|
ctx.logger
|
||||||
|
.debug(format!("Found {} images in use", in_use_images.len()));
|
||||||
|
|
||||||
// Complete in_use field
|
// Complete in_use field
|
||||||
images.iter_mut().for_each(|image| {
|
images.iter_mut().for_each(|image| {
|
||||||
@@ -204,10 +207,7 @@ pub async fn get_updates(
|
|||||||
}
|
}
|
||||||
// Await all the futures
|
// Await all the futures
|
||||||
let images = join_all(handles).await;
|
let images = join_all(handles).await;
|
||||||
let mut updates: Vec<Update> = images
|
let mut updates: Vec<Update> = images.iter().map(|image| image.to_update()).collect();
|
||||||
.iter()
|
|
||||||
.map(|image| image.to_update())
|
|
||||||
.collect();
|
|
||||||
updates.extend_from_slice(&remote_updates);
|
updates.extend_from_slice(&remote_updates);
|
||||||
updates
|
updates
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user