Pint
This commit is contained in:
@@ -2,35 +2,28 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Downloads;
|
||||
use App\Models\PopularMonthly;
|
||||
use App\Models\PopularWeekly;
|
||||
use App\Models\PopularDaily;
|
||||
|
||||
use Conner\Tagging\Taggable;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Maize\Markable\Markable;
|
||||
use Maize\Markable\Models\Like;
|
||||
|
||||
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||
use Spatie\Sitemap\Tags\Url;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Maize\Markable\Markable;
|
||||
use Maize\Markable\Models\Like;
|
||||
use Spatie\Sitemap\Contracts\Sitemapable;
|
||||
use Spatie\Sitemap\Tags\Url;
|
||||
|
||||
class Episode extends Model implements Sitemapable
|
||||
{
|
||||
use Markable, Taggable;
|
||||
use HasFactory;
|
||||
use Markable, Taggable;
|
||||
use Searchable;
|
||||
|
||||
protected static $marks = [
|
||||
Like::class
|
||||
Like::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -49,14 +42,14 @@ class Episode extends Model implements Sitemapable
|
||||
public function toSearchableArray()
|
||||
{
|
||||
return [
|
||||
'title' => $this->title,
|
||||
'title_search' => $this->title_search,
|
||||
'title_jpn' => $this->title_jpn,
|
||||
'slug' => $this->slug,
|
||||
'description' => $this->description,
|
||||
'tags' => $this->tagNames(),
|
||||
'release_date' => $this->release_date,
|
||||
'created_at' => $this->created_at,
|
||||
'title' => $this->title,
|
||||
'title_search' => $this->title_search,
|
||||
'title_jpn' => $this->title_jpn,
|
||||
'slug' => $this->slug,
|
||||
'description' => $this->description,
|
||||
'tags' => $this->tagNames(),
|
||||
'release_date' => $this->release_date,
|
||||
'created_at' => $this->created_at,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -125,7 +118,7 @@ class Episode extends Model implements Sitemapable
|
||||
*/
|
||||
public function viewCount(): int
|
||||
{
|
||||
return cache()->remember('episodeViews' . $this->id, 300, fn() => $this->view_count);
|
||||
return cache()->remember('episodeViews'.$this->id, 300, fn () => $this->view_count);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +134,7 @@ class Episode extends Model implements Sitemapable
|
||||
$index = floor(log($this->viewCount(), 1000));
|
||||
$shortNumber = $this->viewCount() / pow(1000, $index);
|
||||
|
||||
return round($shortNumber, 0) . $units[$index - 1];
|
||||
return round($shortNumber, 0).$units[$index - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +142,7 @@ class Episode extends Model implements Sitemapable
|
||||
*/
|
||||
public function likeCount(): int
|
||||
{
|
||||
return cache()->remember('episodeLikes' . $this->id, 300, fn() => $this->likes->count());
|
||||
return cache()->remember('episodeLikes'.$this->id, 300, fn () => $this->likes->count());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +150,7 @@ class Episode extends Model implements Sitemapable
|
||||
*/
|
||||
public function commentCount(): int
|
||||
{
|
||||
return cache()->remember('episodeComments' . $this->id, 300, fn() => $this->comments->count());
|
||||
return cache()->remember('episodeComments'.$this->id, 300, fn () => $this->comments->count());
|
||||
}
|
||||
|
||||
public function comments()
|
||||
@@ -180,6 +173,7 @@ class Episode extends Model implements Sitemapable
|
||||
|
||||
$problematicResults .= $pTag;
|
||||
}
|
||||
|
||||
return $problematicResults;
|
||||
}
|
||||
|
||||
@@ -202,17 +196,17 @@ class Episode extends Model implements Sitemapable
|
||||
*/
|
||||
public function hasAutoTrans(): bool
|
||||
{
|
||||
return cache()->remember('mt' . $this->id, 900, fn() => $this->subtitles()->exists());
|
||||
return cache()->remember('mt'.$this->id, 900, fn () => $this->subtitles()->exists());
|
||||
}
|
||||
|
||||
public function is48Fps(): bool
|
||||
{
|
||||
return cache()->remember('48fps' . $this->id, 900, fn() => $this->interpolated);
|
||||
return cache()->remember('48fps'.$this->id, 900, fn () => $this->interpolated);
|
||||
}
|
||||
|
||||
public function isUHD48Fps(): bool
|
||||
{
|
||||
return cache()->remember('48fpsUHD' . $this->id, 900, fn() => $this->interpolated_uhd);
|
||||
return cache()->remember('48fpsUHD'.$this->id, 900, fn () => $this->interpolated_uhd);
|
||||
}
|
||||
|
||||
public function getResolution(): string
|
||||
@@ -226,7 +220,7 @@ class Episode extends Model implements Sitemapable
|
||||
|
||||
public function userWatched(int $user_id): bool
|
||||
{
|
||||
return cache()->remember('user' . $user_id . 'watched' . $this->id, 300, fn() => Watched::where('user_id', $user_id)->where('episode_id', $this->id)->exists());
|
||||
return cache()->remember('user'.$user_id.'watched'.$this->id, 300, fn () => Watched::where('user_id', $user_id)->where('episode_id', $this->id)->exists());
|
||||
}
|
||||
|
||||
public function watched(): HasMany
|
||||
@@ -234,15 +228,16 @@ class Episode extends Model implements Sitemapable
|
||||
return $this->hasMany(Watched::class);
|
||||
}
|
||||
|
||||
public function getDownloadByType(string $type): Downloads | null
|
||||
public function getDownloadByType(string $type): ?Downloads
|
||||
{
|
||||
$cacheKey = "episode_{$this->id}_download_{$type}";
|
||||
|
||||
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($type) {
|
||||
return $this->downloads()->where('type', $type)->first();
|
||||
});
|
||||
}
|
||||
|
||||
public function toSitemapTag(): Url | string | array
|
||||
public function toSitemapTag(): Url|string|array
|
||||
{
|
||||
return Url::create(route('hentai.index', $this->slug))
|
||||
->setLastModificationDate(Carbon::create($this->created_at));
|
||||
|
||||
Reference in New Issue
Block a user