From 9c7c451b4db0d3283ec1b603507438388d073abc Mon Sep 17 00:00:00 2001 From: DariusIII Date: Wed, 28 Aug 2019 15:40:11 +0200 Subject: [PATCH] Start removing watson/rememberable usage --- Changelog | 1 + app/Models/Category.php | 50 +++++++++++++++++++++++++++++++++++------ app/Models/Release.php | 12 ---------- composer.json | 2 +- composer.lock | 2 +- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Changelog b/Changelog index 6b2e4e688..e8dc9ddcc 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-08-28 DariusIII + * Chg: Start removing watson/rememberable usage * Chg: Update fideloper/proxy to version 4.2 * Chg: Update laravel/framework (v5.8.33 => v5.8.34) 2019-08-27 DariusIII diff --git a/app/Models/Category.php b/app/Models/Category.php index 667dc83eb..1706c8662 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -2,8 +2,8 @@ namespace App\Models; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; -use Watson\Rememberable\Rememberable; use Illuminate\Database\Eloquent\Model; /** @@ -32,7 +32,6 @@ use Illuminate\Database\Eloquent\Model; */ class Category extends Model { - use Rememberable; /** * Category constants. @@ -273,15 +272,24 @@ class Category extends Model */ public static function getRecentlyAdded() { - return self::query() + $expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); + $result = Cache::get(md5('RecentlyAdded')); + if ($result !== null) { + return $result; + } + + $result = self::query() ->with('parent') - ->remember(config('nntmux.cache_expiry_long')) ->where('r.adddate', '>', now()->subWeek()) ->select(['root_categories_id', DB::raw('COUNT(r.id) as count'), 'title']) ->join('releases as r', 'r.categories_id', '=', 'categories.id') ->groupBy('title') ->orderBy('count', 'desc') ->get(); + + Cache::put(md5('RecentlyAdded'), $result, $expiresAt); + + return $result; } /** @@ -385,7 +393,16 @@ class Category extends Model */ public static function getChildren($categoryId) { - return RootCategory::remember(config('nntmux.cache_expiry_long'))->find($categoryId)->categories; + $expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); + $result = Cache::get(md5($categoryId)); + if ($result !== null) { + return $result; + } + + $result = RootCategory::find($categoryId)->categories; + Cache::put(md5($categoryId), $result, $expiresAt); + + return $result; } /** @@ -421,7 +438,16 @@ class Category extends Model public static function getByIds($ids) { if (\count($ids) > 0) { - return self::query()->remember(config('nntmux.cache_expiry_long'))->whereIn('id', $ids)->get(); + $expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); + $result = Cache::get(md5(implode(',', $ids))); + if ($result !== null) { + return $result; + } + $result = self::query()->whereIn('id', $ids)->get(); + + Cache::put(md5(md5(implode(',', $ids))), $result, $expiresAt); + + return $result; } return false; @@ -508,7 +534,17 @@ class Category extends Model */ public static function getForApi() { - return RootCategory::query()->remember(config('nntmux.cache_expiry_long'))->select(['id', 'title'])->where('status', '=', self::STATUS_ACTIVE)->get(); + $expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long')); + $result = Cache::get(md5('ForApi')); + if ($result !== null) { + return $result; + } + + $result = RootCategory::query()->select(['id', 'title'])->where('status', '=', self::STATUS_ACTIVE)->get(); + + Cache::put(md5('ForApi'), $result, $expiresAt); + + return $result; } /** diff --git a/app/Models/Release.php b/app/Models/Release.php index a1c6d060f..73dda540b 100644 --- a/app/Models/Release.php +++ b/app/Models/Release.php @@ -458,18 +458,6 @@ class Release extends Model ->paginate(config('nntmux.items_per_page')); } - /** - * Get count for admin release list page. - * - * @return int - */ - public static function getReleasesCount(): int - { - $res = self::query()->remember(config('nntmux.cache_expiry_medium'))->count(['id']); - - return $res ?? 0; - } - /** * @param $guid * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static|static[] diff --git a/composer.json b/composer.json index f134605bb..89b920d14 100755 --- a/composer.json +++ b/composer.json @@ -110,7 +110,7 @@ "foolz/sphinxql-query-builder": "^2.0", "genealabs/laravel-caffeine": "^0.8.1", "geoip2/geoip2": "^2.9", - "google/recaptcha": "~1.1", + "google/recaptcha": "^1.2", "guzzlehttp/guzzle": "^6.3", "imdbphp/imdbphp": "^6.0", "intervention/image": "^2.4", diff --git a/composer.lock b/composer.lock index 0458f5e36..2ef5aff1f 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "405362c3086de940a1c11ab664323bc5", + "content-hash": "7cf8649c308d35ecf455a69ab0a86af9", "packages": [ { "name": "aharen/omdbapi",