mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ReleaseStat extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public static function insertRecentlyAdded(): void
|
|
{
|
|
$categories = Category::query()
|
|
->with('parent')
|
|
->where('r.adddate', '>', now()->subWeek())
|
|
->select([
|
|
'categories.id',
|
|
'root_categories_id',
|
|
DB::raw('COUNT(r.id) as count'),
|
|
'categories.title',
|
|
])
|
|
->join('releases as r', 'r.categories_id', '=', 'categories.id')
|
|
->whereNotIn('categories.id', [10, 20]) // Exclude OTHER_MISC and OTHER_HASHED
|
|
->groupBy('categories.id', 'root_categories_id', 'categories.title')
|
|
->orderByDesc('count')
|
|
->get();
|
|
|
|
foreach ($categories as $category) {
|
|
// Build the category display name with root category prefix
|
|
$categoryDisplay = $category->parent
|
|
? $category->parent->title.' > '.$category->title
|
|
: $category->title;
|
|
|
|
// Check if we already have the information and if we do just update the count
|
|
if (self::query()->where('category', $categoryDisplay)->exists()) {
|
|
self::query()->where('category', $categoryDisplay)->update(['count' => $category->count]);
|
|
|
|
continue;
|
|
}
|
|
self::query()->create(['category' => $categoryDisplay, 'count' => $category->count]);
|
|
}
|
|
}
|
|
|
|
public static function getRecentlyAdded(): array
|
|
{
|
|
return self::query()->select(['category', 'count'])->get()->toArray();
|
|
}
|
|
}
|