diff --git a/app/Actions/PlayerPerSeason.php b/app/Actions/PlayerPerSeason.php index 6a417793..99ec477f 100644 --- a/app/Actions/PlayerPerSeason.php +++ b/app/Actions/PlayerPerSeason.php @@ -2,6 +2,7 @@ namespace App\Actions; +use App\Models\SofaScorePlayerCache; use App\Models\SofaScorePlayerPerSeason; use App\Models\StatistikoDetail; use App\Models\StatistikoPlayer; @@ -10,6 +11,9 @@ class PlayerPerSeason { public static function run() { + // when data changes clear player chche + SofaScorePlayerCache::truncate(); + $res = StatistikoDetail::query()->select('ss_player_id', 'ss_team_id')->get(); foreach ($res as $val) { diff --git a/app/Filament/Pages/Selections/Helper/GetSeason.php b/app/Filament/Pages/Selections/Helper/GetSeason.php index ac19c532..5e275bb5 100644 --- a/app/Filament/Pages/Selections/Helper/GetSeason.php +++ b/app/Filament/Pages/Selections/Helper/GetSeason.php @@ -15,9 +15,9 @@ class GetSeason $season = []; if ($seasonmode == 'halfyear') { if ((int) date('m') > 7) - $season[] = $date->format('y') . '/' . $date->format('y') + 1; + $season[] = (string) $date->format('y') . '/' . $date->format('y') + 1; else - $season[] = $date->format('y') - 1 . '/' . $date->format('y'); + $season[] = (string) $date->format('y') - 1 . '/' . $date->format('y'); } else { $season[] = (string) $date->year; } diff --git a/app/Filament/Pages/Selections/LoadPlayer.php b/app/Filament/Pages/Selections/LoadPlayer.php index 63d2afc1..fe6ba220 100644 --- a/app/Filament/Pages/Selections/LoadPlayer.php +++ b/app/Filament/Pages/Selections/LoadPlayer.php @@ -4,6 +4,7 @@ namespace App\Filament\Pages\Selections; use App\Filament\Pages\Selections\Helper\GetSeason; use App\Filament\Pages\Selections\LoadPositions; +use App\Models\SofaScorePlayerCache; use App\Models\SofaScorePlayerPerSeason; use App\Models\StatistikoEvent; use Filament\Schemas\Components\Utilities\Get; @@ -16,7 +17,15 @@ class LoadPlayer $team_position = $get('team_position'); $sofascore_category_id = $get('sofascore_category_id'); $season = $get('season'); - $season = GetSeason::load($season, $sofascore_category_id); + $seasonmode = $get('seasonmode'); + + $season = GetSeason::load($season, $seasonmode); + + $hash = hash('crc32', $team_id . $team_position . $sofascore_category_id . serialize($season)); + $cached_players = SofaScorePlayerCache::where('hash', $hash)->value('players'); + if ($cached_players) { + return $cached_players; + } $matches = StatistikoEvent::whereIn('season', $season) ->where(function ($query) use ($team_id, $team_position) { @@ -38,7 +47,6 @@ class LoadPlayer $player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->whereIn('season', $season)->get(); - $arr = []; foreach ($player as $val) { if ($val->details) { @@ -108,6 +116,10 @@ class LoadPlayer $result[$position][$player_id] = '' . $val['player_name'] . ' ' . $position . '
' . $infostring . '
'; } } + + if ($result) + SofaScorePlayerCache::updateOrCreate(['hash' => $hash], ['players' => $result]); + return $result; } diff --git a/app/Filament/Pages/Statistic.php b/app/Filament/Pages/Statistic.php index 31bea3ae..1e76cc60 100644 --- a/app/Filament/Pages/Statistic.php +++ b/app/Filament/Pages/Statistic.php @@ -6,7 +6,6 @@ use App\Actions\LoadSofaScoreCategory; use App\Actions\LoadStatisticFixturesLeaguesOptions; use App\Actions\LoadStatisticFixturesMatchOptions; use App\Filament\Pages\Selections\LoadPlayer; -use App\Filament\Pages\Selections\LoadSeasons; use App\Models\SofaScoreCategory; use App\Models\SofaScoreRosa; use App\Models\StatisticFixtures; diff --git a/app/Models/SofaScorePlayerCache.php b/app/Models/SofaScorePlayerCache.php new file mode 100644 index 00000000..339a0087 --- /dev/null +++ b/app/Models/SofaScorePlayerCache.php @@ -0,0 +1,21 @@ + 'array' + ]; + + protected $fillable = [ + 'hash', + 'players', + ]; +} diff --git a/database/migrations/2026_08_31_055104_create_sofa_score_player_caches_table.php b/database/migrations/2026_08_31_055104_create_sofa_score_player_caches_table.php new file mode 100644 index 00000000..136b0d0c --- /dev/null +++ b/database/migrations/2026_08_31_055104_create_sofa_score_player_caches_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('hash')->index(); + $table->json('players'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sofa_score_player_caches'); + } +};