players cache wip
This commit is contained in:
1 parent
713da3b266
commit
1949a06480
6 files changed
+70
-5
No files matched your search
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Actions;
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\SofaScorePlayerCache;
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
use App\Models\SofaScorePlayerPerSeason;
|
||||||
use App\Models\StatistikoDetail;
|
use App\Models\StatistikoDetail;
|
||||||
use App\Models\StatistikoPlayer;
|
use App\Models\StatistikoPlayer;
|
||||||
@@ -10,6 +11,9 @@ class PlayerPerSeason
|
|||||||
{
|
{
|
||||||
public static function run()
|
public static function run()
|
||||||
{
|
{
|
||||||
|
// when data changes clear player chche
|
||||||
|
SofaScorePlayerCache::truncate();
|
||||||
|
|
||||||
$res = StatistikoDetail::query()->select('ss_player_id', 'ss_team_id')->get();
|
$res = StatistikoDetail::query()->select('ss_player_id', 'ss_team_id')->get();
|
||||||
|
|
||||||
foreach ($res as $val) {
|
foreach ($res as $val) {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ class GetSeason
|
|||||||
$season = [];
|
$season = [];
|
||||||
if ($seasonmode == 'halfyear') {
|
if ($seasonmode == 'halfyear') {
|
||||||
if ((int) date('m') > 7)
|
if ((int) date('m') > 7)
|
||||||
$season[] = $date->format('y') . '/' . $date->format('y') + 1;
|
$season[] = (string) $date->format('y') . '/' . $date->format('y') + 1;
|
||||||
else
|
else
|
||||||
$season[] = $date->format('y') - 1 . '/' . $date->format('y');
|
$season[] = (string) $date->format('y') - 1 . '/' . $date->format('y');
|
||||||
} else {
|
} else {
|
||||||
$season[] = (string) $date->year;
|
$season[] = (string) $date->year;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Filament\Pages\Selections;
|
|||||||
|
|
||||||
use App\Filament\Pages\Selections\Helper\GetSeason;
|
use App\Filament\Pages\Selections\Helper\GetSeason;
|
||||||
use App\Filament\Pages\Selections\LoadPositions;
|
use App\Filament\Pages\Selections\LoadPositions;
|
||||||
|
use App\Models\SofaScorePlayerCache;
|
||||||
use App\Models\SofaScorePlayerPerSeason;
|
use App\Models\SofaScorePlayerPerSeason;
|
||||||
use App\Models\StatistikoEvent;
|
use App\Models\StatistikoEvent;
|
||||||
use Filament\Schemas\Components\Utilities\Get;
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
@@ -16,7 +17,15 @@ class LoadPlayer
|
|||||||
$team_position = $get('team_position');
|
$team_position = $get('team_position');
|
||||||
$sofascore_category_id = $get('sofascore_category_id');
|
$sofascore_category_id = $get('sofascore_category_id');
|
||||||
$season = $get('season');
|
$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)
|
$matches = StatistikoEvent::whereIn('season', $season)
|
||||||
->where(function ($query) use ($team_id, $team_position) {
|
->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();
|
$player = SofaScorePlayerPerSeason::with('details')->where('ss_team_id', $team_id)->whereIn('season', $season)->get();
|
||||||
|
|
||||||
|
|
||||||
$arr = [];
|
$arr = [];
|
||||||
foreach ($player as $val) {
|
foreach ($player as $val) {
|
||||||
if ($val->details) {
|
if ($val->details) {
|
||||||
@@ -108,6 +116,10 @@ class LoadPlayer
|
|||||||
$result[$position][$player_id] = '<span class="text-green-600 dark:text-green-500 cursor-pointer"><b>' . $val['player_name'] . '</b> ' . $position . '<br>' . $infostring . '</span>';
|
$result[$position][$player_id] = '<span class="text-green-600 dark:text-green-500 cursor-pointer"><b>' . $val['player_name'] . '</b> ' . $position . '<br>' . $infostring . '</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($result)
|
||||||
|
SofaScorePlayerCache::updateOrCreate(['hash' => $hash], ['players' => $result]);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use App\Actions\LoadSofaScoreCategory;
|
|||||||
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
use App\Actions\LoadStatisticFixturesLeaguesOptions;
|
||||||
use App\Actions\LoadStatisticFixturesMatchOptions;
|
use App\Actions\LoadStatisticFixturesMatchOptions;
|
||||||
use App\Filament\Pages\Selections\LoadPlayer;
|
use App\Filament\Pages\Selections\LoadPlayer;
|
||||||
use App\Filament\Pages\Selections\LoadSeasons;
|
|
||||||
use App\Models\SofaScoreCategory;
|
use App\Models\SofaScoreCategory;
|
||||||
use App\Models\SofaScoreRosa;
|
use App\Models\SofaScoreRosa;
|
||||||
use App\Models\StatisticFixtures;
|
use App\Models\StatisticFixtures;
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class SofaScorePlayerCache extends Model
|
||||||
|
{
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $primaryKey = 'hash';
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'players' => 'array'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'hash',
|
||||||
|
'players',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('sofa_score_player_caches', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('hash')->index();
|
||||||
|
$table->json('players');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sofa_score_player_caches');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user