mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 00:01:21 +00:00
@@ -8,8 +8,6 @@ use App\Models\UserMovie;
|
||||
use App\Models\UserSerie;
|
||||
use Blacklight\NZB;
|
||||
use Blacklight\Releases;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -30,10 +28,7 @@ class RSS extends ApiController
|
||||
$this->releases = new Releases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Release[]|Collection|mixed
|
||||
*/
|
||||
public function getRss($cat, $videosId, $aniDbID, int $userID = 0, int $airDate = -1, int $limit = 100, int $offset = 0)
|
||||
public function getRss($cat, $videosId, $aniDbID, int $userID = 0, int $airDate = -1, int $limit = 100, int $offset = 0): mixed
|
||||
{
|
||||
$catSearch = $cartSearch = '';
|
||||
$catLimit = 'AND r.categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER;
|
||||
@@ -86,22 +81,12 @@ class RSS extends ApiController
|
||||
$limit === -1 ? '' : ' LIMIT '.$limit.' OFFSET '.$offset
|
||||
);
|
||||
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
|
||||
$result = Cache::get(md5($sql));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = Release::fromQuery($sql);
|
||||
Cache::put(md5($sql), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
|
||||
return Release::fromQuery($sql);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder|Collection
|
||||
*/
|
||||
public function getShowsRss(int $limit, int $userID = 0, array $excludedCats = [], int $airDate = -1)
|
||||
public function getShowsRss(int $limit, int $userID = 0, array $excludedCats = [], int $airDate = -1): mixed
|
||||
{
|
||||
$sql = sprintf(
|
||||
"
|
||||
@@ -140,22 +125,12 @@ class RSS extends ApiController
|
||||
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : ''
|
||||
);
|
||||
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
|
||||
$result = Cache::get(md5($sql));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = Release::fromQuery($sql);
|
||||
Cache::put(md5($sql), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
|
||||
return Release::fromQuery($sql);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Release[]|Collection|mixed
|
||||
*/
|
||||
public function getMyMoviesRss(int $limit, int $userID = 0, array $excludedCats = [])
|
||||
public function getMyMoviesRss(int $limit, int $userID = 0, array $excludedCats = []): mixed
|
||||
{
|
||||
$sql = sprintf(
|
||||
"
|
||||
@@ -192,17 +167,9 @@ class RSS extends ApiController
|
||||
! empty($limit) ? sprintf(' LIMIT %d OFFSET 0', $limit > 100 ? 100 : $limit) : ''
|
||||
);
|
||||
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium'));
|
||||
$result = Cache::get(md5($sql));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = Release::fromQuery($sql);
|
||||
|
||||
Cache::put(md5($sql), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible(md5($sql), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($sql) {
|
||||
return Release::fromQuery($sql);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-32
@@ -363,16 +363,9 @@ class Category extends Model
|
||||
*/
|
||||
public static function getChildren($categoryId)
|
||||
{
|
||||
$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;
|
||||
return Cache::flexible(md5($categoryId), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($categoryId) {
|
||||
return RootCategory::find($categoryId)->categories;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,16 +399,9 @@ class Category extends Model
|
||||
public static function getByIds($ids)
|
||||
{
|
||||
if (\count($ids) > 0) {
|
||||
$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 Cache::flexible(md5(md5(implode(',', $ids))), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($ids) {
|
||||
return self::query()->whereIn('id', $ids)->get();
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -477,21 +463,13 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* Get categories for the API.
|
||||
*/
|
||||
public static function getForApi()
|
||||
{
|
||||
$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;
|
||||
return Cache::flexible('ForApi', [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () {
|
||||
return RootCategory::query()->select(['id', 'title'])->where('status', '=', self::STATUS_ACTIVE)->get();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+34
-60
@@ -333,70 +333,44 @@ class Release extends Model
|
||||
return self::whereAnidbid($anidbID)->update(['anidbid' => -1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|\Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public static function getReleases()
|
||||
public static function getReleases(): mixed
|
||||
{
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
|
||||
$releases = Cache::get(md5('releases'));
|
||||
if ($releases !== null) {
|
||||
return $releases;
|
||||
}
|
||||
|
||||
$releases = self::query()
|
||||
|
||||
->where('nzbstatus', '=', NZB::NZB_ADDED)
|
||||
->select(['releases.*', 'g.name as group_name', 'c.title as category_name'])
|
||||
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id')
|
||||
->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id')
|
||||
->get();
|
||||
|
||||
Cache::put(md5('releases'), $releases, $expiresAt);
|
||||
|
||||
return $releases;
|
||||
return Cache::flexible('Releases', [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () {
|
||||
return self::query()
|
||||
->where('nzbstatus', '=', NZB::NZB_ADDED)
|
||||
->select(['releases.*', 'g.name as group_name', 'c.title as category_name'])
|
||||
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id')
|
||||
->leftJoin('usenet_groups as g', 'g.id', '=', 'releases.groups_id')
|
||||
->get();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for admin page release-list.
|
||||
*
|
||||
*
|
||||
* @return LengthAwarePaginator|mixed
|
||||
*/
|
||||
public static function getReleasesRange()
|
||||
public static function getReleasesRange(): mixed
|
||||
{
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
|
||||
$releases = Cache::get(md5('releasesRange'));
|
||||
if ($releases !== null) {
|
||||
return $releases;
|
||||
}
|
||||
|
||||
$releases = self::query()
|
||||
->where('nzbstatus', '=', NZB::NZB_ADDED)
|
||||
->select(
|
||||
[
|
||||
'releases.id',
|
||||
'releases.name',
|
||||
'releases.searchname',
|
||||
'releases.size',
|
||||
'releases.guid',
|
||||
'releases.totalpart',
|
||||
'releases.postdate',
|
||||
'releases.adddate',
|
||||
'releases.grabs',
|
||||
'cp.title as parent_category',
|
||||
'c.title as sub_category',
|
||||
DB::raw('CONCAT(cp.title, ' > ', c.title) AS category_name'),
|
||||
]
|
||||
)
|
||||
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id')
|
||||
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id')
|
||||
->orderByDesc('releases.postdate')
|
||||
->paginate(config('nntmux.items_per_page'));
|
||||
|
||||
Cache::put(md5('releasesRange'), $releases, $expiresAt);
|
||||
|
||||
return $releases;
|
||||
return Cache::flexible('releasesRange', [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () {
|
||||
return self::query()
|
||||
->where('nzbstatus', '=', NZB::NZB_ADDED)
|
||||
->select(
|
||||
[
|
||||
'releases.id',
|
||||
'releases.name',
|
||||
'releases.searchname',
|
||||
'releases.size',
|
||||
'releases.guid',
|
||||
'releases.totalpart',
|
||||
'releases.postdate',
|
||||
'releases.adddate',
|
||||
'releases.grabs',
|
||||
'cp.title as parent_category',
|
||||
'c.title as sub_category',
|
||||
DB::raw('CONCAT(cp.title, ' > ', c.title) AS category_name'),
|
||||
]
|
||||
)
|
||||
->leftJoin('categories as c', 'c.id', '=', 'releases.categories_id')
|
||||
->leftJoin('root_categories as cp', 'cp.id', '=', 'c.root_categories_id')
|
||||
->orderByDesc('releases.postdate')
|
||||
->paginate(config('nntmux.items_per_page'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user