mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Cache cell state to fix #14852
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user