From eea327c4764e32fbd9878e81eff9dc8e8abee3b4 Mon Sep 17 00:00:00 2001 From: Filip Lelek Date: Wed, 7 Aug 2024 16:27:23 +0200 Subject: [PATCH] Fix: Cache renewal doesn't update the sha --- fplus-database/src/database/applications.rs | 16 ++++++++++------ fplus-lib/src/core/mod.rs | 11 +++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fplus-database/src/database/applications.rs b/fplus-database/src/database/applications.rs index 4baf2db..43bf5ec 100644 --- a/fplus-database/src/database/applications.rs +++ b/fplus-database/src/database/applications.rs @@ -328,8 +328,8 @@ pub async fn merge_application_by_pr_number( * @param repo: String - The repository name * @param pr_number: u64 - The PR number * @param app_file: String - The application file - * @param sha: Option - The SHA of the application * @param path: Option - The path of the application + * @param sha: Option - The SHA of the application * * # Returns * @return Result - The result of the operation @@ -341,6 +341,7 @@ pub async fn update_application( pr_number: u64, app_file: String, path: Option, + sha: Option, ) -> Result { let conn = get_database_connection().await?; @@ -348,12 +349,15 @@ pub async fn update_application( Ok(existing_application) => { let mut active_application: ActiveModel = existing_application.into_active_model(); active_application.application = Set(Some(app_file.clone())); - //Calculate SHA - let mut hasher = Sha1::new(); - let application = format!("blob {}\x00{}", app_file.len(), app_file); - hasher.update(application.as_bytes()); - let file_sha = format!("{:x}", hasher.finalize()); + let file_sha = sha.unwrap_or_else(|| { + //Calculate SHA + let mut hasher = Sha1::new(); + let application = format!("blob {}\x00{}", app_file.len(), app_file); + hasher.update(application.as_bytes()); + format!("{:x}", hasher.finalize()) + }); active_application.sha = Set(Some(file_sha)); + if let Some(path) = path { active_application.path = Set(Some(path)); }; diff --git a/fplus-lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs index 9c9025e..6a46c62 100644 --- a/fplus-lib/src/core/mod.rs +++ b/fplus-lib/src/core/mod.rs @@ -896,6 +896,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&app_file).unwrap(), Some(app_path.clone()), + None, ) .await; @@ -1056,6 +1057,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&app_file).unwrap(), Some(self.file_name.clone()), + None, ) .await; Self::issue_start_sign_dc( @@ -1213,6 +1215,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&app_file).unwrap(), Some(self.file_name.clone()), + None, ) .await { @@ -1983,6 +1986,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&app_file).unwrap(), Some(ldn_application.file_name.clone()), + None, ) .await; } @@ -2054,6 +2058,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&db_application_file).unwrap(), Some(filename.clone()), + None, ) .await; @@ -2351,6 +2356,7 @@ impl LDNApplication { pr_number, file_content.clone(), Some(filename.clone()), + None, ) .await .map_err(|e| { @@ -2716,6 +2722,7 @@ impl LDNApplication { number, serde_json::to_string_pretty(&app_file).unwrap(), Some(application_model.path.clone().unwrap()), + None, ) .await; } @@ -3467,6 +3474,7 @@ _The initial issue can be edited in order to solve the request of the verifier. db_app.pr_number as u64, serde_json::to_string_pretty(&gh_app.application_file).unwrap(), None, + Some(gh_app.sha.clone()), ) .await .unwrap(); @@ -3548,6 +3556,7 @@ _The initial issue can be edited in order to solve the request of the verifier. 0, serde_json::to_string_pretty(&gh_app.application_file).unwrap(), Some(gh_app.path.clone()), + Some(gh_app.sha.clone()), ) .await .unwrap(); @@ -3770,6 +3779,7 @@ _The initial issue can be edited in order to solve the request of the verifier. })?, serde_json::to_string_pretty(&application_file).unwrap(), app_model.path.clone(), + None, ) .await .expect("Failed to update_application in DB!"); @@ -3909,6 +3919,7 @@ _The initial issue can be edited in order to solve the request of the verifier. })?, serde_json::to_string_pretty(&application_file).unwrap(), app_model.path.clone(), + None, ) .await .expect("Failed to update_application in DB!");