Skip to content

Nexus datastore: combine update_available_artifact_{upsert,hard_delete_outdated} #766

@iliana

Description

@iliana

pub async fn update_available_artifact_upsert(
&self,
artifact: UpdateAvailableArtifact,
) -> CreateResult<UpdateAvailableArtifact> {
use db::schema::update_available_artifact::dsl;
diesel::insert_into(dsl::update_available_artifact)
.values(artifact.clone())
.on_conflict((dsl::name, dsl::version, dsl::kind))
.do_update()
.set(artifact.clone())
.returning(UpdateAvailableArtifact::as_returning())
.get_result_async(self.pool())
.await
.map_err(|e| public_error_from_diesel_pool(e, ErrorHandler::Server))
}
pub async fn update_available_artifact_hard_delete_outdated(
&self,
current_targets_role_version: i64,
) -> DeleteResult {
// We use the `targets_role_version` column in the table to delete any old rows, keeping
// the table in sync with the current copy of artifacts.json.
use db::schema::update_available_artifact::dsl;
diesel::delete(dsl::update_available_artifact)
.filter(dsl::targets_role_version.lt(current_targets_role_version))
.execute_async(self.pool())
.await
.map(|_rows_deleted| ())
.map_err(|e| {
Error::internal_error(&format!(
"error deleting outdated available artifacts: {:?}",
e
))
})
}

These are two separate datastore methods, but are always called together. Combine these into one method and use a transaction to ensure the list of artifacts in the database remains consistent.

(From #717)

Metadata

Metadata

Assignees

Labels

Update SystemReplacing old bits with newer, cooler bitscleanupCode cleanlinessnexusRelated to nexus

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions