Skip to content

Commit

Permalink
Don't display the attribute changed message multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Sep 4, 2024
1 parent f1af191 commit 681f92e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Services/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getCachableMatrix(Response $response): Collection
'urlIsCachable' => $this->urlIsCachable(),
'responseIsCachable' => $this->responseIsCachable($response),
'statusCodeIsCachable' => $this->statusCodeIsCachable($response),
'METHOD' => EdgeFlush::getRequest()->getMethod(),
]);
}

Expand Down
18 changes: 12 additions & 6 deletions src/Services/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Entity

public array $relations = [];

protected Collection $modelNames;

public function __construct(Model $model, string|null $event = null)
{
$this->absorb($model);
Expand Down Expand Up @@ -126,7 +128,7 @@ public function makeEvent(Model $model, string|null $event = null): void

public function getDirtyModelNames(): Collection
{
$modelNames = Helpers::collect();
$this->modelNames = $this->modelNames ?? Helpers::collect();

foreach ($this->attributes as $key => $value) {
$castType = gettype($value);
Expand All @@ -143,9 +145,11 @@ public function getDirtyModelNames(): Collection
$modelName .= "[attribute:{$key}]";
}

Helpers::debug("ATTRIBUTE CHANGED: {$modelName}");
if (!isset($this->modelNames[$modelName])) {
Helpers::debug("ATTRIBUTE CHANGED: {$modelName}");

$modelNames[$modelName] = $modelName;
$this->modelNames[$modelName] = $modelName;
}
}
}
}
Expand All @@ -159,14 +163,16 @@ public function getDirtyModelNames(): Collection
$modelName .= "[relation:{$name}]";
}

Helpers::debug("RELATION CHANGED: {$modelName}");
if (!isset($this->modelNames[$modelName])) {
Helpers::debug("RELATION CHANGED: {$modelName}");

$modelNames[$modelName] = $modelName;
$this->modelNames[$modelName] = $modelName;
}
}
}
}

return $modelNames;
return $this->modelNames;
}

public function getOriginal(string $key): mixed
Expand Down

0 comments on commit 681f92e

Please sign in to comment.