🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-09-28 20:19:09.0 +04:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-09-28 20:19:15.0 +04:00:00
commit
8febc8a517bc9e774078965eab0143e7bade3f3e [patch]
tree
2887c42a2b9899f20bd8c325df7e97336a770cab
parent
b15e37cfa968b2c8baa63d0574243ede63f7a50e
download
8febc8a517bc9e774078965eab0143e7bade3f3e.tar.gz

Perform repository operation on commit page in parallel



Diff

 src/methods/repo/commit.rs | 53 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/src/methods/repo/commit.rs b/src/methods/repo/commit.rs
index 3c82c5d..53f8a19 100644
--- a/src/methods/repo/commit.rs
+++ a/src/methods/repo/commit.rs
@@ -5,7 +5,7 @@
use serde::Deserialize;

use crate::{
    git::Commit,
    git::{Commit, OpenRepository},
    into_response,
    methods::{
        filters,
@@ -39,26 +39,11 @@
) -> Result<impl IntoResponse> {
    let open_repo = git.repo(repository_path, query.branch.clone()).await?;

    let dl_branch = if let Some(branch) = query.branch.clone() {
        branch
    } else {
        Arc::from(
            open_repo
                .clone()
                .default_branch()
                .await
                .ok()
                .flatten()
                .unwrap_or_else(|| "master".to_string()),
        )
    };
    let (dl_branch, commit) = tokio::try_join!(
        fetch_dl_branch(query.branch.clone(), open_repo.clone()),
        fetch_commit(query.id.as_deref(), open_repo),
    )?;

    let commit = if let Some(commit) = query.id.as_deref() {
        open_repo.commit(commit, true).await?
    } else {
        Arc::new(open_repo.latest_commit(true).await?)
    };

    Ok(into_response(View {
        repo,
        commit,
@@ -66,4 +51,32 @@
        id: query.id,
        dl_branch,
    }))
}

async fn fetch_commit(
    commit_id: Option<&str>,
    open_repo: Arc<OpenRepository>,
) -> Result<Arc<Commit>> {
    Ok(if let Some(commit) = commit_id {
        open_repo.commit(commit, true).await?
    } else {
        Arc::new(open_repo.latest_commit(true).await?)
    })
}

async fn fetch_dl_branch(
    branch: Option<Arc<str>>,
    open_repo: Arc<OpenRepository>,
) -> Result<Arc<str>> {
    if let Some(branch) = branch.clone() {
        Ok(branch)
    } else {
        Ok(Arc::from(
            open_repo
                .clone()
                .default_branch()
                .await?
                .unwrap_or_else(|| "master".to_string()),
        ))
    }
}