From 164a649cd46db3a9b6f60c471ee39eacc5532fa1 Mon Sep 17 00:00:00 2001 From: Refringe Date: Sun, 8 Sep 2024 22:06:52 -0400 Subject: [PATCH] Removes old SPT versions from search results The global search results are now limited to mods tagged with the last three minor SPT versions, like the mod listing filters. I'm not 100% sure about this change. Open to suggestions and revisiting this in the future. Resolves #26 --- app/Models/Mod.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Models/Mod.php b/app/Models/Mod.php index 030c7db..84d6e22 100644 --- a/app/Models/Mod.php +++ b/app/Models/Mod.php @@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Laravel\Scout\Searchable; @@ -144,6 +145,14 @@ class Mod extends Model return false; } + // Ensure the latest SPT version is within the last three minor versions. + $activeSptVersions = Cache::remember('active-spt-versions', 60 * 60, function () { + return SptVersion::getVersionsForLastThreeMinors(); + }); + if (! in_array($latestVersion->latestSptVersion()->first()->version, $activeSptVersions->pluck('version')->toArray())) { + return false; + } + // All conditions are met; the mod should be searchable. return true; }