mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-10 11:51:57 +02:00
fix(models): let a snapshot race resolve to the version that won
Two sends of the same request can both miss the content-hash lookup and race to insert. The unique index settles it; the loser wants exactly what the winner wrote, not an error that costs its response a version link.
This commit is contained in:
@@ -50,11 +50,22 @@ impl<'a> ClientDb<'a> {
|
||||
workspace_id: request.workspace_id().to_string(),
|
||||
model_type: request.model_type().to_string(),
|
||||
model_id: request.id().to_string(),
|
||||
content_hash,
|
||||
content_hash: content_hash.clone(),
|
||||
document,
|
||||
reason,
|
||||
..Default::default()
|
||||
})?;
|
||||
});
|
||||
|
||||
let version = match version {
|
||||
Ok(version) => version,
|
||||
// Two sends of the same request can both miss the lookup above and
|
||||
// race to insert. The unique index settles it, and the loser wants
|
||||
// exactly what the winner wrote.
|
||||
Err(err) => match self.find_version_by_hash(request.id(), &content_hash) {
|
||||
Some(existing) => return Ok(existing),
|
||||
None => return Err(err),
|
||||
},
|
||||
};
|
||||
|
||||
self.prune_model_versions(request.id())?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user