From 850b2aadd402ab80c0d2c371fe7be3066271a1ab Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 May 2021 18:10:00 +0200 Subject: Only update repository description if the description changed Check the repository description that comes back from the GitHub API against our cached description in the database. Only write the new description if it changed so we can avoid writing to the file in that case. --- src/database.rs | 8 ++++++++ src/main.rs | 14 +++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/database.rs b/src/database.rs index 1dac44f..ac5ef3b 100644 --- a/src/database.rs +++ b/src/database.rs @@ -12,6 +12,14 @@ pub struct Repo { updated_at: Option, } +impl Repo { + pub fn description(&self) -> &str { + self.description + .as_deref() + .unwrap_or("") + } +} + impl From<&github::Repo> for Repo { fn from(repo: &github::Repo) -> Self { Self { diff --git a/src/main.rs b/src/main.rs index 2a3e988..697ca7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,9 +62,9 @@ async fn main() { let db_repo = database::Repo::from(&repo); match db.repo_get(id).await { - Ok(_) => { + Ok(current_repo) => { if db.repo_is_updated(&db_repo).await.unwrap() { - update(&path, &repo).unwrap(); + update(&path, ¤t_repo, &repo).unwrap(); db.repo_update(&db_repo).await.unwrap(); } @@ -116,12 +116,16 @@ fn mirror>( fn update>( repo_path: P, - repo: &github::Repo, + current_repo: &database::Repo, + updated_repo: &github::Repo, ) -> anyhow::Result<()> { git::update(&repo_path)?; - // TODO: Don't write if description is the same - git::update_description(&repo_path, repo.description())?; + let remote_description = updated_repo.description(); + + if current_repo.description() != remote_description { + git::update_description(&repo_path, remote_description)?; + } Ok(()) } -- cgit v1.2.3