db and query optimization compl

This commit is contained in:
salam committed 2026-01-04 06:29:11 +01:00
1 parent 9d2a8ce628
commit 40d97327d4
24 files changed
+145 -126

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ class Odds
262148 TOTALS OVER TIME
11534337 GG/NG (both teams to score)
5242880 DOUBLE CHANCE
7340033 TO PROGRESS (to_qualify)
7340033 TO PROGRESS (to qualify)
6291457 DRAW NO BET
Not used:
@@ -52,7 +52,31 @@ class EventResource extends Resource
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->where('starttime', '>', Carbon::now());
$query = parent::getEloquentQuery()
->where('starttime', '>', Carbon::now())
->with('competition_group')
->with('country')
->with('home')
->with('away');
if (in_array(1, EventsTable::$bettype_settings)) {
$query->with('odds_3way.bookmaker');
}
if (in_array(2, EventsTable::$bettype_settings)) {
$query->with('odds_dc.bookmaker');
}
if (in_array(3, EventsTable::$bettype_settings)) {
$query->with('odds_dnb.bookmaker');
}
if (in_array(4, EventsTable::$bettype_settings)) {
$query->with('odds_ggng.bookmaker');
}
if (in_array(5, EventsTable::$bettype_settings)) {
$query->with('odds_tq.bookmaker');
}
if (in_array(6, EventsTable::$bettype_settings)) {
$query->with('odds_total.bookmaker');
}
return $query;
}
}
+9 -19
View File
@@ -2,15 +2,12 @@
namespace App\Filament\Tables\Columns;
use App\Models\Odds3way;
use Filament\Tables\Columns\Column;
class Column3way extends Column
{
protected string $view = 'filament.tables.columns.column_3way';
protected $data;
protected ?array $max;
protected ?array $min;
@@ -33,26 +30,19 @@ class Column3way extends Column
public function loadData($record)
{
$this->data = Odds3way::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['h3w'] = $record->odds_3way->max('h3w');
$this->min['h3w'] = $record->odds_3way->min('h3w');
$this->max['h3w'] = $this->data->max('h3w');
$this->min['h3w'] = $this->data->min('h3w');
$this->max['d3w'] = $record->odds_3way->max('d3w');
$this->min['d3w'] = $record->odds_3way->min('d3w');
$this->max['d3w'] = $this->data->max('d3w');
$this->min['d3w'] = $this->data->min('d3w');
$this->max['a3w'] = $record->odds_3way->max('a3w');
$this->min['a3w'] = $record->odds_3way->min('a3w');
$this->max['a3w'] = $this->data->max('a3w');
$this->min['a3w'] = $this->data->min('a3w');
$this->max['margin'] = $record->odds_3way->max('margin');
$this->min['margin'] = $record->odds_3way->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_3way) ? true : false;
}
public function getMax()
+9 -19
View File
@@ -2,7 +2,6 @@
namespace App\Filament\Tables\Columns;
use App\Models\OddsDc;
use Filament\Tables\Columns\Column;
class ColumnDc extends Column
@@ -13,8 +12,6 @@ class ColumnDc extends Column
protected ?array $min;
protected $data;
protected ?array $bookmakers;
protected ?bool $has_data;
@@ -33,26 +30,19 @@ class ColumnDc extends Column
public function loadData($record)
{
$this->data = OddsDc::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['dc1x'] = $record->odds_dc->max('dc1x');
$this->min['dc1x'] = $record->odds_dc->min('dc1x');
$this->max['dc1x'] = $this->data->max('dc1x');
$this->min['dc1x'] = $this->data->min('dc1x');
$this->max['dc12'] = $record->odds_dc->max('dc12');
$this->min['dc12'] = $record->odds_dc->min('dc12');
$this->max['dc12'] = $this->data->max('dc12');
$this->min['dc12'] = $this->data->min('dc12');
$this->max['dcx2'] = $record->odds_dc->max('dcx2');
$this->min['dcx2'] = $record->odds_dc->min('dcx2');
$this->max['dcx2'] = $this->data->max('dcx2');
$this->min['dcx2'] = $this->data->min('dcx2');
$this->max['margin'] = $record->odds_dc->max('margin');
$this->min['margin'] = $record->odds_dc->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_dc) ? true : false;
}
public function getMax()
+7 -17
View File
@@ -2,7 +2,6 @@
namespace App\Filament\Tables\Columns;
use App\Models\OddsDnb;
use Filament\Tables\Columns\Column;
class ColumnDnb extends Column
@@ -13,8 +12,6 @@ class ColumnDnb extends Column
protected ?array $min;
protected $data;
protected ?array $bookmakers;
protected ?bool $has_data;
@@ -33,23 +30,16 @@ class ColumnDnb extends Column
public function loadData($record)
{
$this->data = OddsDnb::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['dnb1'] = $record->odds_dnb->max('dnb1');
$this->min['dnb1'] = $record->odds_dnb->min('dnb1');
$this->max['dnb1'] = $this->data->max('dnb1');
$this->min['dnb1'] = $this->data->min('dnb1');
$this->max['dnb2'] = $record->odds_dnb->max('dnb2');
$this->min['dnb2'] = $record->odds_dnb->min('dnb2');
$this->max['dnb2'] = $this->data->max('dnb2');
$this->min['dnb2'] = $this->data->min('dnb2');
$this->max['margin'] = $record->odds_dnb->max('margin');
$this->min['margin'] = $record->odds_dnb->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_dnb) ? true : false;
}
public function getMax()
+7 -17
View File
@@ -2,7 +2,6 @@
namespace App\Filament\Tables\Columns;
use App\Models\OddsGgng;
use Filament\Tables\Columns\Column;
class ColumnGgng extends Column
@@ -13,8 +12,6 @@ class ColumnGgng extends Column
protected ?array $min;
protected $data;
protected ?array $bookmakers;
protected ?bool $has_data;
@@ -33,23 +30,16 @@ class ColumnGgng extends Column
public function loadData($record)
{
$this->data = OddsGgng::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['gg'] = $record->odds_ggng->max('gg');
$this->min['gg'] = $record->odds_ggng->min('gg');
$this->max['gg'] = $this->data->max('gg');
$this->min['gg'] = $this->data->min('gg');
$this->max['ng'] = $record->odds_ggng->max('ng');
$this->min['ng'] = $record->odds_ggng->min('ng');
$this->max['ng'] = $this->data->max('ng');
$this->min['ng'] = $this->data->min('ng');
$this->max['margin'] = $record->odds_ggng->max('margin');
$this->min['margin'] = $record->odds_ggng->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_ggng) ? true : false;
}
public function getMax()
+7 -17
View File
@@ -2,7 +2,6 @@
namespace App\Filament\Tables\Columns;
use App\Models\OddsTotal;
use Filament\Tables\Columns\Column;
class ColumnTotal extends Column
@@ -13,8 +12,6 @@ class ColumnTotal extends Column
protected ?array $min;
protected $data;
protected ?array $bookmakers;
protected ?bool $has_data;
@@ -33,23 +30,16 @@ class ColumnTotal extends Column
public function loadData($record)
{
$this->data = OddsTotal::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['over'] = $record->odds_total->max('over');
$this->min['over'] = $record->odds_total->min('over');
$this->max['over'] = $this->data->max('over');
$this->min['over'] = $this->data->min('over');
$this->max['under'] = $record->odds_total->max('under');
$this->min['under'] = $record->odds_total->min('under');
$this->max['under'] = $this->data->max('under');
$this->min['under'] = $this->data->min('under');
$this->max['margin'] = $record->odds_total->max('margin');
$this->min['margin'] = $record->odds_total->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_total) ? true : false;
}
public function getMax()
+7 -17
View File
@@ -2,7 +2,6 @@
namespace App\Filament\Tables\Columns;
use App\Models\OddsQualify;
use Filament\Tables\Columns\Column;
class ColumnTq extends Column
@@ -13,8 +12,6 @@ class ColumnTq extends Column
protected ?array $min;
protected $data;
protected ?array $bookmakers;
protected ?bool $has_data;
@@ -33,23 +30,16 @@ class ColumnTq extends Column
public function loadData($record)
{
$this->data = OddsQualify::with('bookmaker')->where('event_id', $record->id)->get();
$this->max['htq'] = $record->odds_tq->max('htq');
$this->min['htq'] = $record->odds_tq->min('htq');
$this->max['htq'] = $this->data->max('htq');
$this->min['htq'] = $this->data->min('htq');
$this->max['atq'] = $record->odds_tq->max('atq');
$this->min['atq'] = $record->odds_tq->min('atq');
$this->max['atq'] = $this->data->max('atq');
$this->min['atq'] = $this->data->min('atq');
$this->max['margin'] = $record->odds_tq->max('margin');
$this->min['margin'] = $record->odds_tq->min('margin');
$this->max['margin'] = $this->data->max('margin');
$this->min['margin'] = $this->data->min('margin');
$this->has_data = count($this->data) ? true : false;
}
public function getData()
{
return $this->data;
$this->has_data = count($record->odds_tq) ? true : false;
}
public function getMax()
+55
View File
@@ -67,4 +67,59 @@ class Event extends Model
{
return $this->belongsTo(Element::class);
}
public function odds_2way()
{
return $this->hasMany(Odds2way::class);
}
public function odds_2way_s1()
{
return $this->hasMany(Odds2wayS1::class);
}
public function odds_3way()
{
return $this->hasMany(Odds3way::class);
}
public function odds_dc()
{
return $this->hasMany(OddsDc::class);
}
public function odds_dnb()
{
return $this->hasMany(OddsDnb::class);
}
public function odds_ggng()
{
return $this->hasMany(OddsGgng::class);
}
public function odds_handicap()
{
return $this->hasMany(OddsHandicap::class);
}
public function odds_handicap_q1()
{
return $this->hasMany(OddsHandicapQ1::class);
}
public function odds_total()
{
return $this->hasMany(OddsTotal::class);
}
public function odds_total_q1()
{
return $this->hasMany(OddsTotalQ1::class);
}
public function odds_tq()
{
return $this->hasMany(OddsTq::class);
}
}
@@ -4,9 +4,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OddsQualify extends Model
class OddsTq extends Model
{
protected $table = 'odds_qualify';
protected $table = 'odds_tq';
protected $fillable = [
'id',
@@ -11,7 +11,7 @@ return new class extends Migration
*/
public function up(): void
{
Schema::create('odds_qualify', function (Blueprint $table) {
Schema::create('odds_tq', function (Blueprint $table) {
$table->id();
$table->foreignId('event_id')->index()->constrained()->cascadeOnDelete()->references('id')->on('events');
$table->integer('sport_id')->index()->references('id')->on('sports');
@@ -33,6 +33,6 @@ return new class extends Migration
*/
public function down(): void
{
Schema::dropIfExists('odds_qualify');
Schema::dropIfExists('odds_tq');
}
};
+1 -1
View File
@@ -18,7 +18,7 @@ class MultilineSettingSeeder extends Seeder
(2, 1, 'DOUBLE CHANCE', 'DC', 'odds_dc', 4, 1, '2025-12-14 09:31:22', '2025-12-14 09:32:55'),
(3, 1, 'DRAW NO BET', 'DNB', 'odds_dnb', 4, 0, '2025-12-14 09:31:42', '2025-12-14 09:31:42'),
(4, 1, 'GOAL NO GOAL', 'GGNG', 'odds_ggng', 4, 0, '2025-12-14 09:31:56', '2025-12-14 09:31:56'),
(5, 1, 'TO QUALIFY', 'TQ', 'odds_qualify', 4, 0, '2025-12-14 09:32:19', '2025-12-14 09:32:19'),
(5, 1, 'TO QUALIFY', 'TQ', 'odds_tq', 4, 0, '2025-12-14 09:32:19', '2025-12-14 09:32:19'),
(6, 1, 'TOTALS', 'OU', 'odds_totals', 4, 1, '2025-12-14 09:32:38', '2025-12-14 09:32:38'),
(7, 3, 'MONEY LINE', 'ML', 'odds_2ways', 4, 0, '2025-12-14 09:37:32', '2025-12-14 09:37:32'),
(8, 3, 'HANDICAP', 'HC', 'odds_handicaps', 4, 1, '2025-12-14 09:38:05', '2025-12-14 09:38:05'),
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['1X', '12', 'X2']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_dc as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['DNB1', 'DNB2']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_dnb as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['GG', 'NG']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_ggng as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['O', 'U', 'T']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_total as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['H', 'A']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_tq as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -11,7 +11,7 @@
@include('filament.tables.columns.multiline.label', ['labels' => ['1', 'X', '2']])
@foreach ($getBookmaker() as $bookmaker_id)
@foreach ($getData() as $item)
@foreach ($record->odds_3way as $item)
@if ($item->bookmaker_id == $bookmaker_id)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_3way as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_dc as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_dnb as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_ggng as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_total as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',
@@ -10,7 +10,7 @@
$min = $getMin();
@endphp
@foreach ($getData() as $item)
@foreach ($record->odds_tq as $item)
@include('filament.tables.columns.multiline.bkm', [
'bookmaker_id' => $item->bookmaker_id,
'icon' => $item->bookmaker->icon ?? '',