mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 00:01:21 +00:00
Start removing watson/rememberable usage
This commit is contained in:
+43
-7
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user