summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-08-01 15:08:29 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-08-01 15:08:29 +0200
commit77ffc402fee0d75703fa9864939de02b8e4ebc49 (patch)
tree130ad925b737d9eb9e52a12c3d3ea722b3cfa275
parentd0091f9b4f2eb13f745bf20923c5a713f76616b5 (diff)
Make repo state fetching async
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml1
-rw-r--r--src/model/state.rs12
-rw-r--r--src/routes/branch.rs2
-rw-r--r--src/routes/repo.rs2
-rw-r--r--src/routes/tree.rs2
5 files changed, 11 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 69997a8..6192cd4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,7 @@ clap = "3.0.0-beta.2"
derive_more = "0.99"
either = "1.6"
env_logger = "0.8"
+futures = "0.3"
getset = "0.1"
git2 = "0.13"
handlebars = "4.1"
diff --git a/src/model/state.rs b/src/model/state.rs
index 608bc9f..1e32bfa 100644
--- a/src/model/state.rs
+++ b/src/model/state.rs
@@ -53,18 +53,20 @@ impl RepoState {
Ok(RepoState { name, repo })
}
- pub fn stat(&self) -> Result<cached::Return<RepositoryStat>> {
+ pub async fn stat(&self) -> Result<cached::Return<RepositoryStat>> {
+ let (branches, tags) = futures::try_join!(self.branch_names(), self.tag_names())?;
+
Ok(cached::Return::new(RepositoryStat {
- branches: self.branch_names()?.value,
- tags: self.tag_names()?.value,
+ branches: branches.value,
+ tags: tags.value,
}))
}
- pub fn branch_names(&self) -> Result<cached::Return<Vec<String>>> {
+ pub async fn branch_names(&self) -> Result<cached::Return<Vec<String>>> {
get_branch_names(&self.name, &self.repo)
}
- pub fn tag_names(&self) -> Result<cached::Return<Vec<String>>> {
+ pub async fn tag_names(&self) -> Result<cached::Return<Vec<String>>> {
get_tag_names(&self.name, &self.repo)
}
}
diff --git a/src/routes/branch.rs b/src/routes/branch.rs
index 2a49c69..205d891 100644
--- a/src/routes/branch.rs
+++ b/src/routes/branch.rs
@@ -13,7 +13,7 @@ pub async fn branch<'a>(web::Path((repo_name, branch_name)): web::Path<(String,
let repo_lock = repo_state.lock()
.map_err(|_| crate::routes::error::RepositoryError::Str("Lock error".to_string()))?;
- let repo_stat = repo_lock.stat().map_err(|e| RepositoryError::Str(e.to_string()))?;
+ let repo_stat = repo_lock.stat().await.map_err(|e| RepositoryError::Str(e.to_string()))?;
let tree = repo_lock.repo()
.find_branch(&branch_name, git2::BranchType::Local)
diff --git a/src/routes/repo.rs b/src/routes/repo.rs
index e2a8c45..0c79071 100644
--- a/src/routes/repo.rs
+++ b/src/routes/repo.rs
@@ -14,7 +14,7 @@ pub async fn repo_index<'a>(web::Path(repo_name): web::Path<String>, data: web::
let repo_lock = repo_state.lock()
.map_err(|_| crate::routes::error::RepositoryError::Str("Lock error".to_string()))?;
- let repo_stat = repo_lock.stat().map_err(|e| RepositoryError::Str(e.to_string()))?;
+ let repo_stat = repo_lock.stat().await.map_err(|e| RepositoryError::Str(e.to_string()))?;
let repo = repo_lock.repo();
let tree = repo.find_branch(&default_branch_name, git2::BranchType::Local)
.map_err(|_| crate::routes::error::RepositoryError::Str("Branch not found".to_string()))?
diff --git a/src/routes/tree.rs b/src/routes/tree.rs
index 12953ff..f4be25e 100644
--- a/src/routes/tree.rs
+++ b/src/routes/tree.rs
@@ -15,7 +15,7 @@ pub async fn tree<'a>(web::Path((repo_name, branch_name, tree_path)): web::Path<
let repo_lock = repo_state.lock()
.map_err(|_| RepositoryError::Str("Lock error".to_string()))?;
- let repo_stat = repo_lock.stat().map_err(|e| RepositoryError::Str(e.to_string()))?;
+ let repo_stat = repo_lock.stat().await.map_err(|e| RepositoryError::Str(e.to_string()))?;
let root = repo_lock.repo()
.find_branch(&branch_name, git2::BranchType::Local)
.map_err(|_| crate::routes::error::RepositoryError::Str("Branch not found".to_string()))?