From f1552399f1391efa014ee1de645560b4f53ecae0 Mon Sep 17 00:00:00 2001 From: Maciej Rymarz <59456825+mako321@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:34:45 +0100 Subject: [PATCH] Add QueryCachable trait (#199) * Add QueryCachable trait * WIP --- src/Models/H5PContent.php | 3 ++- src/Models/H5PContentLibrary.php | 3 ++- src/Models/H5PLibrary.php | 3 ++- tests/Repositories/H5PRepositoryTest.php | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Models/H5PContent.php b/src/Models/H5PContent.php index 1d8c8c07..50b65827 100644 --- a/src/Models/H5PContent.php +++ b/src/Models/H5PContent.php @@ -2,6 +2,7 @@ namespace EscolaLms\HeadlessH5P\Models; +use EscolaLms\Core\Models\Traits\QueryCacheable; use EscolaLms\Core\Models\User; use EscolaLms\HeadlessH5P\Database\Factories\H5PContentFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -89,7 +90,7 @@ class H5PContent extends Model { - use HasFactory; + use HasFactory, QueryCacheable; protected $table = 'hh5p_contents'; diff --git a/src/Models/H5PContentLibrary.php b/src/Models/H5PContentLibrary.php index 9a8946db..737be904 100644 --- a/src/Models/H5PContentLibrary.php +++ b/src/Models/H5PContentLibrary.php @@ -2,6 +2,7 @@ namespace EscolaLms\HeadlessH5P\Models; +use EscolaLms\Core\Models\Traits\QueryCacheable; use EscolaLms\HeadlessH5P\Database\Factories\H5PContentLibraryFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -9,7 +10,7 @@ class H5PContentLibrary extends Model { - use HasFactory; + use HasFactory, QueryCacheable; public $incrementing = false; diff --git a/src/Models/H5PLibrary.php b/src/Models/H5PLibrary.php index cb848bc6..fa99ed9d 100644 --- a/src/Models/H5PLibrary.php +++ b/src/Models/H5PLibrary.php @@ -2,6 +2,7 @@ namespace EscolaLms\HeadlessH5P\Models; +use EscolaLms\Core\Models\Traits\QueryCacheable; use EscolaLms\HeadlessH5P\Database\Factories\H5PLibraryFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -117,7 +118,7 @@ class H5PLibrary extends Model { - use HasFactory; + use HasFactory, QueryCacheable; protected $table = 'hh5p_libraries'; diff --git a/tests/Repositories/H5PRepositoryTest.php b/tests/Repositories/H5PRepositoryTest.php index fd3b5942..eac0307a 100644 --- a/tests/Repositories/H5PRepositoryTest.php +++ b/tests/Repositories/H5PRepositoryTest.php @@ -126,7 +126,7 @@ public function testDeleteLibraryUsageShouldDeleteLibrariesById(): void $this->repository->deleteLibraryUsage($h5pContent->getKey()); - $this->assertCount(0, H5PContent::find($h5pContent->getKey())->libraries); + $this->assertCount(0, $h5pContent->refresh()->libraries); } public function testDeleteLibraryUsageShouldFailWhenContentNotExists(): void