Fix rack order race condition allowing slots/power to exceed DC limits
CI / build-and-push (push) Successful in 47s
CI / build-and-push (push) Successful in 47s
Rapid clicks on order rack bypassed capacity checks because usedSlots and usedPowerKW were only updated during the tick. Now both the store action and UI compute slot/power usage live from racks + pipeline, so each order immediately reflects in the next check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -196,8 +196,14 @@ export const useGameStore = create<Store>()(
|
||||
if (!dc || dc.status !== 'operational') return s;
|
||||
|
||||
const tierConfig = DC_TIER_CONFIGS[dc.tier];
|
||||
if (dc.usedSlots >= tierConfig.rackSlots) return s;
|
||||
if (dc.usedPowerKW + sku.powerDrawKW > tierConfig.powerBudgetKW) return s;
|
||||
const pipelineForDc = s.infrastructure.rackPipeline.filter(o => o.dataCenterId === dataCenterId).length;
|
||||
const actualUsedSlots = dc.racks.length + pipelineForDc;
|
||||
const pipelinePowerForDc = s.infrastructure.rackPipeline
|
||||
.filter(o => o.dataCenterId === dataCenterId)
|
||||
.reduce((sum, o) => sum + RACK_SKU_CONFIGS[o.skuId].powerDrawKW, 0);
|
||||
const actualUsedPower = dc.racks.reduce((sum, r) => sum + RACK_SKU_CONFIGS[r.skuId].powerDrawKW, 0) + pipelinePowerForDc;
|
||||
if (actualUsedSlots >= tierConfig.rackSlots) return s;
|
||||
if (actualUsedPower + sku.powerDrawKW > tierConfig.powerBudgetKW) return s;
|
||||
|
||||
const order = {
|
||||
id: uuid(),
|
||||
|
||||
Reference in New Issue
Block a user