Skip to content

Commit

Permalink
Fix: Cache renewal doesn't update the sha
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-neti authored and kacperzuk-neti committed Aug 8, 2024
1 parent c86f216 commit acb9640
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 10 additions & 6 deletions fplus-database/src/database/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> - The SHA of the application
* @param path: Option<String> - The path of the application
* @param sha: Option<String> - The SHA of the application
*
* # Returns
* @return Result<ApplicationModel, sea_orm::DbErr> - The result of the operation
Expand All @@ -341,19 +341,23 @@ pub async fn update_application(
pr_number: u64,
app_file: String,
path: Option<String>,
sha: Option<String>,
) -> Result<ApplicationModel, sea_orm::DbErr> {
let conn = get_database_connection().await?;

match get_application(id.clone(), owner.clone(), repo.clone(), Some(pr_number)).await {
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));
};
Expand Down
11 changes: 11 additions & 0 deletions fplus-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ impl LDNApplication {
number,
serde_json::to_string_pretty(&app_file).unwrap(),
Some(app_path.clone()),
None,
)
.await;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1213,6 +1215,7 @@ impl LDNApplication {
number,
serde_json::to_string_pretty(&app_file).unwrap(),
Some(self.file_name.clone()),
None,
)
.await
{
Expand Down Expand Up @@ -1983,6 +1986,7 @@ impl LDNApplication {
number,
serde_json::to_string_pretty(&app_file).unwrap(),
Some(ldn_application.file_name.clone()),
None,
)
.await;
}
Expand Down Expand Up @@ -2054,6 +2058,7 @@ impl LDNApplication {
number,
serde_json::to_string_pretty(&db_application_file).unwrap(),
Some(filename.clone()),
None,
)
.await;

Expand Down Expand Up @@ -2351,6 +2356,7 @@ impl LDNApplication {
pr_number,
file_content.clone(),
Some(filename.clone()),
None,
)
.await
.map_err(|e| {
Expand Down Expand Up @@ -2716,6 +2722,7 @@ impl LDNApplication {
number,
serde_json::to_string_pretty(&app_file).unwrap(),
Some(application_model.path.clone().unwrap()),
None,
)
.await;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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!");
Expand Down

0 comments on commit acb9640

Please sign in to comment.