Skip to content

Commit ca86656

Browse files
store: Address comments and move evaluations until they are needed.
Move deployment exists check into the graft_base branch so the DB exists call is only executed when we actually are creating a graft. Rename needs_check → should_validate and add a clear comment describing the validation cases. Avoid calling layout unless validation is required and keep shard connections short‑lived (acquire/drop per use) to reduce connection deadlock risk. Signed-off-by: Maksim Dimitrov <dimitrov.maksim@gmail.com>
1 parent 0d307c9 commit ca86656

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

store/postgres/src/subgraph_store.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,23 +365,21 @@ impl SubgraphStore {
365365
.get(&site.shard)
366366
.ok_or_else(|| StoreError::UnknownShard(site.shard.to_string()))?;
367367

368-
let mut shard_conn = deployment_store.get_replica_conn(ReplicaId::Main).await?;
369-
let needs_check = if site_was_created {
370-
true
371-
} else {
372-
// If deployment does not exist, but site exists it means
373-
// that we are recovering from a failed deployment creation with an orphaned site.
374-
// In that case, we should check graft compatibility again.
375-
let exists = crate::deployment::exists(&mut shard_conn, &site).await?;
376-
!exists
377-
};
378-
379368
if let Some(graft_base) = graft_base {
380-
let base_layout = self.layout(graft_base).await?;
381-
382-
if needs_check {
369+
// Perform schema compatibility validation when:
370+
// - the site was just created (first-time deployment), or
371+
// - the site exists but the deployment is missing (recovering from a failed create).
372+
// The `exists` DB call is only made if `site_was_created` is false.
373+
let should_validate = {
374+
let mut shard_conn = deployment_store.get_replica_conn(ReplicaId::Main).await?;
375+
site_was_created || !crate::deployment::exists(&mut shard_conn, &site).await?
376+
};
377+
378+
if should_validate {
379+
let base_layout = self.layout(graft_base).await?;
383380
let entities_with_causality_region =
384381
deployment.manifest.entities_with_causality_region.clone();
382+
let mut shard_conn = deployment_store.get_replica_conn(ReplicaId::Main).await?;
385383
let catalog = Catalog::for_creation(
386384
&mut shard_conn,
387385
site.cheap_clone(),

0 commit comments

Comments
 (0)