mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-06 20:00:53 +01:00
feat: switch to JoinSet over join_all
Some checks are pending
Debug / Get build version (push) Waiting to run
Debug / Build for linux-x86_64 (push) Blocked by required conditions
Debug / Build for macos-aarch64 (push) Blocked by required conditions
Debug / Build for macos-x86_64 (push) Blocked by required conditions
Debug / Build for windows-x86_64 (push) Blocked by required conditions
Test & Lint / lint (push) Waiting to run
Some checks are pending
Debug / Get build version (push) Waiting to run
Debug / Build for linux-x86_64 (push) Blocked by required conditions
Debug / Build for macos-aarch64 (push) Blocked by required conditions
Debug / Build for macos-x86_64 (push) Blocked by required conditions
Debug / Build for windows-x86_64 (push) Blocked by required conditions
Test & Lint / lint (push) Waiting to run
This commit is contained in:
parent
83fa22f7de
commit
5d62549817
3 changed files with 78 additions and 56 deletions
|
@ -10,7 +10,6 @@ use actix_web::{web, web::Bytes, HttpResponse, Responder};
|
||||||
use async_compression::Level;
|
use async_compression::Level;
|
||||||
use convert_case::{Case, Casing};
|
use convert_case::{Case, Casing};
|
||||||
use fs_err::tokio as fs;
|
use fs_err::tokio as fs;
|
||||||
use futures::{future::join_all, join};
|
|
||||||
use git2::{Remote, Repository, Signature};
|
use git2::{Remote, Repository, Signature};
|
||||||
use pesde::{
|
use pesde::{
|
||||||
manifest::Manifest,
|
manifest::Manifest,
|
||||||
|
@ -31,7 +30,10 @@ use std::{
|
||||||
collections::{BTreeSet, HashMap},
|
collections::{BTreeSet, HashMap},
|
||||||
io::{Cursor, Write},
|
io::{Cursor, Write},
|
||||||
};
|
};
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::{
|
||||||
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
|
task::JoinSet,
|
||||||
|
};
|
||||||
|
|
||||||
fn signature<'a>() -> Signature<'a> {
|
fn signature<'a>() -> Signature<'a> {
|
||||||
Signature::now(
|
Signature::now(
|
||||||
|
@ -487,29 +489,43 @@ pub async fn publish_package(
|
||||||
|
|
||||||
let version_id = VersionId::new(manifest.version.clone(), manifest.target.kind());
|
let version_id = VersionId::new(manifest.version.clone(), manifest.target.kind());
|
||||||
|
|
||||||
let (a, b, c) = join!(
|
let mut tasks = docs_pages
|
||||||
app_state
|
|
||||||
.storage
|
|
||||||
.store_package(&manifest.name, &version_id, bytes.to_vec()),
|
|
||||||
join_all(
|
|
||||||
docs_pages
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(hash, content)| app_state.storage.store_doc(hash, content)),
|
.map(|(hash, content)| {
|
||||||
),
|
let app_state = app_state.clone();
|
||||||
async {
|
async move { app_state.storage.store_doc(hash, content).await }
|
||||||
if let Some(readme) = readme {
|
})
|
||||||
|
.collect::<JoinSet<_>>();
|
||||||
|
|
||||||
|
{
|
||||||
|
let app_state = app_state.clone();
|
||||||
|
let name = manifest.name.clone();
|
||||||
|
let version_id = version_id.clone();
|
||||||
|
|
||||||
|
tasks.spawn(async move {
|
||||||
app_state
|
app_state
|
||||||
.storage
|
.storage
|
||||||
.store_readme(&manifest.name, &version_id, readme)
|
.store_package(&name, &version_id, bytes.to_vec())
|
||||||
.await
|
.await
|
||||||
} else {
|
});
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(readme) = readme {
|
||||||
|
let app_state = app_state.clone();
|
||||||
|
let name = manifest.name.clone();
|
||||||
|
let version_id = version_id.clone();
|
||||||
|
|
||||||
|
tasks.spawn(async move {
|
||||||
|
app_state
|
||||||
|
.storage
|
||||||
|
.store_readme(&name, &version_id, readme)
|
||||||
|
.await
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(res) = tasks.join_next().await {
|
||||||
|
res.unwrap()?;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
a?;
|
|
||||||
b.into_iter().collect::<Result<(), _>>()?;
|
|
||||||
c?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().body(format!(
|
Ok(HttpResponse::Ok().body(format!(
|
||||||
"published {}@{} {}",
|
"published {}@{} {}",
|
||||||
|
|
|
@ -13,7 +13,6 @@ use crate::cli::{
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use fs_err::tokio as fs;
|
use fs_err::tokio as fs;
|
||||||
use futures::future::try_join_all;
|
|
||||||
use pesde::{
|
use pesde::{
|
||||||
download_and_link::{filter_graph, DownloadAndLinkHooks, DownloadAndLinkOptions},
|
download_and_link::{filter_graph, DownloadAndLinkHooks, DownloadAndLinkOptions},
|
||||||
graph::{ConvertableGraph, DependencyGraph, DownloadedGraph},
|
graph::{ConvertableGraph, DependencyGraph, DownloadedGraph},
|
||||||
|
@ -209,7 +208,7 @@ pub async fn install(
|
||||||
|
|
||||||
for target_kind in TargetKind::VARIANTS {
|
for target_kind in TargetKind::VARIANTS {
|
||||||
let folder = manifest.target.kind().packages_folder(target_kind);
|
let folder = manifest.target.kind().packages_folder(target_kind);
|
||||||
let package_dir = project.package_dir();
|
let package_dir = project.package_dir().to_path_buf();
|
||||||
|
|
||||||
deleted_folders
|
deleted_folders
|
||||||
.entry(folder.to_string())
|
.entry(folder.to_string())
|
||||||
|
@ -229,9 +228,10 @@ pub async fn install(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try_join_all(deleted_folders.into_values())
|
let mut tasks = deleted_folders.into_values().collect::<JoinSet<_>>();
|
||||||
.await
|
while let Some(task) = tasks.join_next().await {
|
||||||
.context("failed to remove package folders")?;
|
task.unwrap()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root_progress.reset();
|
root_progress.reset();
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
||||||
source::{IGNORED_DIRS, IGNORED_FILES},
|
source::{IGNORED_DIRS, IGNORED_FILES},
|
||||||
};
|
};
|
||||||
use fs_err::tokio as fs;
|
use fs_err::tokio as fs;
|
||||||
use futures::future::try_join_all;
|
|
||||||
use relative_path::RelativePathBuf;
|
use relative_path::RelativePathBuf;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
@ -16,6 +15,7 @@ use tempfile::Builder;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
pin,
|
pin,
|
||||||
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
|
@ -128,13 +128,15 @@ impl PackageFs {
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
PackageFs::CAS(entries) => {
|
PackageFs::CAS(entries) => {
|
||||||
try_join_all(entries.iter().map(|(path, entry)| {
|
let mut tasks = entries
|
||||||
|
.iter()
|
||||||
|
.map(|(path, entry)| {
|
||||||
let destination = destination.as_ref().to_path_buf();
|
let destination = destination.as_ref().to_path_buf();
|
||||||
let cas_path = cas_path.as_ref().to_path_buf();
|
let cas_path = cas_path.as_ref().to_path_buf();
|
||||||
|
let path = path.to_path(destination);
|
||||||
|
let entry = entry.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let path = path.to_path(destination);
|
|
||||||
|
|
||||||
match entry {
|
match entry {
|
||||||
FsEntry::File(hash) => {
|
FsEntry::File(hash) => {
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
|
@ -158,8 +160,12 @@ impl PackageFs {
|
||||||
|
|
||||||
Ok::<_, std::io::Error>(())
|
Ok::<_, std::io::Error>(())
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
.await?;
|
.collect::<JoinSet<_>>();
|
||||||
|
|
||||||
|
while let Some(task) = tasks.join_next().await {
|
||||||
|
task.unwrap()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PackageFs::Copy(src, target) => {
|
PackageFs::Copy(src, target) => {
|
||||||
fs::create_dir_all(destination.as_ref()).await?;
|
fs::create_dir_all(destination.as_ref()).await?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue