bug fixes

This commit is contained in:
2023-09-02 19:30:45 +10:00
parent c36d4783e7
commit 7cf6b0bba6
5 changed files with 29 additions and 26 deletions

View File

@@ -28,7 +28,7 @@ trait HasAttachments
*/
public function getAttachments(): Collection
{
return Cache::remember($this->cacheKey(), now()->addDays(28), function () {
return Cache::remember($this->attachmentsCacheKey(), now()->addDays(28), function () {
return $this->attachments()->get();
});
}
@@ -61,7 +61,7 @@ trait HasAttachments
}
}
Cache::forget($this->cacheKey());
Cache::forget($this->attachmentsCacheKey());
$this->attachments()->createMany($attachmentItems);
}
@@ -72,7 +72,7 @@ trait HasAttachments
*/
public function deleteAttachments(): void
{
Cache::forget($this->cacheKey());
Cache::forget($this->attachmentsCacheKey());
$this->morphMany(\App\Models\Attachment::class, 'addendum')->delete();
}
@@ -91,7 +91,7 @@ trait HasAttachments
*
* @return string
*/
private function cacheKey(): string
private function attachmentsCacheKey(): string
{
return "attachments:{$this->getTable()}:{$this->id}";
}

View File

@@ -50,6 +50,7 @@ trait HasGallery
}
}
Cache::forget($this->galleryCacheKey());
$this->gallery()->createMany($galleryItems);
}
@@ -65,13 +66,18 @@ trait HasGallery
public function getGallery(): Collection
{
$cacheKey = 'gallery:' . $this->getTable() . ':' . $this->id;
if (Cache::has($cacheKey) === true) {
return Cache::get($cacheKey);
}
return Cache::remember($this->galleryCacheKey(), now()->addDays(28), function () {
return $this->gallery()->get();
});
}
$gallery = $this->morphMany(\App\Models\Gallery::class, 'addendum')->get();
Cache::put($cacheKey, $gallery, now()->addDays(14));
return $gallery;
/**
* Return the attachment cache key.
*
* @return string
*/
private function galleryCacheKey(): string
{
return "gallery:{$this->getTable()}:{$this->id}";
}
}