From fb1101f54d6294bf968a75f6686c98f952aed738 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sat, 14 Jan 2023 23:55:11 -0700 Subject: [PATCH] server/upload-path: Set completeness hint when NAR is deduplicated --- server/src/api/v1/upload_path.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/src/api/v1/upload_path.rs b/server/src/api/v1/upload_path.rs index f3e1aa0..558ca96 100644 --- a/server/src/api/v1/upload_path.rs +++ b/server/src/api/v1/upload_path.rs @@ -224,6 +224,21 @@ async fn upload_path_dedup( .await .map_err(ServerError::database_error)?; + // Also mark the NAR as complete again + // + // This is racy (a chunkref might have been broken in the + // meantime), but it's okay since it's just a hint to + // `get-missing-paths` so clients don't attempt to upload + // again. Also see the comments in `server/src/database/entity/nar.rs`. + Nar::update(nar::ActiveModel { + id: Set(existing_nar.id), + completeness_hint: Set(true), + ..Default::default() + }) + .exec(&txn) + .await + .map_err(ServerError::database_error)?; + txn.commit().await.map_err(ServerError::database_error)?; // Ensure it's not unlocked earlier