Cache cell state to fix #14852

This commit is contained in:
robinmoisson
2025-03-23 09:49:46 +01:00
parent a2a80f634c
commit a36b1822f7
@@ -24,6 +24,13 @@ trait HasCellState
protected ?string $inverseRelationshipName = null;
protected array $cachedStatePerRecordId = [];
protected function getRecordId(): mixed
{
return $this->getRecord()?->getKey();
}
public function inverseRelationship(?string $name): static
{
$this->inverseRelationshipName = $name;
@@ -75,6 +82,10 @@ trait HasCellState
return null;
}
if (array_key_exists($this->getRecordId(), $this->cachedStatePerRecordId)) {
return $this->cachedStatePerRecordId[$this->getRecordId()];
}
$state = ($this->getStateUsing !== null) ?
$this->evaluate($this->getStateUsing) :
$this->getStateFromRecord();
@@ -90,6 +101,8 @@ trait HasCellState
$state = $this->getDefaultState();
}
$this->cachedStatePerRecordId[$this->getRecordId()] = $state;
return $state;
}