fix: 🔥 remove rennokki/laravel-eloquent-query-cache package
This commit is contained in:
parent
8caaff989c
commit
978cfc2109
7 changed files with 48 additions and 150 deletions
|
|
@ -7,7 +7,6 @@ use App\Traits\Models\ActivityLog;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
/**
|
||||
* @property integer $id Brand id.
|
||||
|
|
@ -34,14 +33,6 @@ class Brand extends Model
|
|||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use QueryCacheable;
|
||||
|
||||
/**
|
||||
* The timeout cache for this model.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cacheFor = 0;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -56,18 +47,6 @@ class Brand extends Model
|
|||
'domain',
|
||||
];
|
||||
|
||||
/**
|
||||
* Brand
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
$this->cacheFor = config('api.servicesDBCache') * 60;
|
||||
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ class ModelAnswer extends Model
|
|||
*/
|
||||
protected $table = 'model_answer';
|
||||
|
||||
/**
|
||||
* The primary key for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
/**
|
||||
* @property integer $id Id.
|
||||
|
|
@ -32,14 +32,6 @@ class Service extends Model
|
|||
{
|
||||
use ActivityLog;
|
||||
use HasFactory;
|
||||
use QueryCacheable;
|
||||
|
||||
/**
|
||||
* The timeout cache for this model
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $cacheFor = 0;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -60,18 +52,6 @@ class Service extends Model
|
|||
'bearer_token_date' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Service.
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
parent::__construct($attributes);
|
||||
$this->cacheFor = config('api.servicesDBCache') * 60;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
|
|
@ -86,16 +66,13 @@ class Service extends Model
|
|||
}
|
||||
});
|
||||
static::created(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::updated(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
static::deleted(function () {
|
||||
// * Flush Eloquent cache.
|
||||
self::flushQueryCache();
|
||||
self::resetCache();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -123,21 +100,6 @@ class Service extends Model
|
|||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Set the base cache tags that will be present
|
||||
* on all queries.
|
||||
*
|
||||
* ! This is used to flush caching
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
protected function getCacheBaseTags(): array
|
||||
{
|
||||
return [
|
||||
'crm_services',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new bearer token.
|
||||
*
|
||||
|
|
@ -184,25 +146,21 @@ class Service extends Model
|
|||
*/
|
||||
public static function getFromBearerToken(string $bearerToken): self
|
||||
{
|
||||
$services = static::all();
|
||||
/** @var \App\Models\Service $service */
|
||||
foreach ($services as $service) {
|
||||
$tokenEquals = false;
|
||||
// * Keep compatibility with V2.
|
||||
if (!Hash::needsRehash($bearerToken)) {
|
||||
$tokenEquals = Hash::check($bearerToken, $service->bearer_token);
|
||||
} else {
|
||||
$tokenEquals = $bearerToken === $service->bearer_token;
|
||||
}
|
||||
if ($service->bearer_token and $tokenEquals) {
|
||||
return $service->load([
|
||||
'brand' => function ($query) use ($service) {
|
||||
return $query->cacheTags(["service:{$service->id}:brand"]);
|
||||
},
|
||||
]);
|
||||
$service = static::getServices()->first(function ($service) use ($bearerToken) {
|
||||
if (! $service->bearer_token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !Hash::needsRehash($bearerToken)
|
||||
? Hash::check($bearerToken, $service->bearer_token)
|
||||
: $bearerToken === $service->bearer_token;
|
||||
});
|
||||
|
||||
if (! $service) {
|
||||
throw new ModelNotFoundException('Could not find service from Service Token');
|
||||
}
|
||||
throw new ModelNotFoundException('Could not find service from Service Token');
|
||||
|
||||
return $service->load('brand');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -255,4 +213,27 @@ class Service extends Model
|
|||
// ! Très important hash_equals https://fr.wikipedia.org/wiki/Attaque_temporelle
|
||||
return \hash_equals($calculatedHash, $request->signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cache elements related to this model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function resetCache(): void
|
||||
{
|
||||
Cache::forget('services');
|
||||
self::getServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all services.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getServices(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::remember('services', 86400, function () {
|
||||
return self::query()->orderBy('name', 'ASC')->get();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
"league/csv": "^9.7",
|
||||
"mews/purifier": "^3.4",
|
||||
"propaganistas/laravel-phone": "^5.0",
|
||||
"rennokki/laravel-eloquent-query-cache": "^3.5",
|
||||
"sentry/sentry-laravel": "^4.10",
|
||||
"uwil/admin-secure-laravel": "^3.0",
|
||||
"uwil/k8s-laravel": "^1.4",
|
||||
|
|
|
|||
68
composer.lock
generated
68
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "10dd6c5fb0d61dc72de0093b29cb458b",
|
||||
"content-hash": "ee8bdd66e3ddef5e410f2b2a7d852c2b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "24slides/laravel-saml2",
|
||||
|
|
@ -5073,72 +5073,6 @@
|
|||
],
|
||||
"time": "2024-04-27T21:32:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rennokki/laravel-eloquent-query-cache",
|
||||
"version": "3.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/renoki-co/laravel-eloquent-query-cache.git",
|
||||
"reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/renoki-co/laravel-eloquent-query-cache/zipball/094d1d165d219a1c0bcdc9cf966a72d78f63c46e",
|
||||
"reference": "094d1d165d219a1c0bcdc9cf966a72d78f63c46e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/database": "^10.5|^11.33",
|
||||
"illuminate/support": "^10.5|^11.33"
|
||||
},
|
||||
"require-dev": {
|
||||
"chelout/laravel-relationship-events": "^1.5|^2.0|^3.0",
|
||||
"laravel/legacy-factories": "^1.4",
|
||||
"livewire/livewire": "dev-main",
|
||||
"mockery/mockery": "^1.6",
|
||||
"orchestra/testbench": "^8.1.1|^9",
|
||||
"phpunit/phpunit": "^9.5.25|^10|^11"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Rennokki\\QueryCache\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alex Renoki",
|
||||
"email": "alex@renoki.org",
|
||||
"homepage": "https://github.com/rennokki",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Adding cache on your Laravel Eloquent queries' results is now a breeze.",
|
||||
"homepage": "https://github.com/renoki-co/laravel-eloquent-query-cache",
|
||||
"keywords": [
|
||||
"caching",
|
||||
"eloquent",
|
||||
"laravel",
|
||||
"query",
|
||||
"remember",
|
||||
"sql"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/renoki-co/laravel-eloquent-query-cache/issues",
|
||||
"source": "https://github.com/renoki-co/laravel-eloquent-query-cache/tree/3.5.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/rennokki",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-30T17:53:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "robrichards/xmlseclibs",
|
||||
"version": "3.1.3",
|
||||
|
|
|
|||
2
database/.gitignore
vendored
2
database/.gitignore
vendored
|
|
@ -1,2 +0,0 @@
|
|||
*.sqlite
|
||||
*.sqlite-journal
|
||||
Loading…
Add table
Reference in a new issue