Skip to content

Commit

Permalink
fix(mining ledger): Fix loading time issue due to prices eager-load (e…
Browse files Browse the repository at this point in the history
…veseat#65)

Since last update applied for price updating, every retrieved ledger entry is leading to a load
from historical_price table. On ledger display, it's causing big issues.
  • Loading branch information
warlof authored Oct 28, 2018
1 parent 77b52bb commit 817483c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Repositories/Character/MiningLedger.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ trait MiningLedger
public function getCharacterLedger(int $character_id, bool $get = true)
{

$ledger = CharacterMining::select('date', 'solar_system_id', 'type_id', 'quantity')
$ledger = CharacterMining::select('character_minings.date', 'solar_system_id', 'character_minings.type_id')
->join('invTypes', 'invTypes.typeID', 'character_minings.type_id')
->leftJoin('historical_prices', function ($join) {
$join->on('historical_prices.type_id', '=', 'character_minings.type_id')
->on('historical_prices.date', '=', 'character_minings.date');
})
->where('character_id', $character_id);

if (! $get)
Expand Down
11 changes: 9 additions & 2 deletions src/Repositories/Corporation/MiningLedger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace Seat\Services\Repositories\Corporation;

use Illuminate\Support\Facades\DB;
use Seat\Eveapi\Models\Industry\CharacterMining;

/**
Expand Down Expand Up @@ -64,11 +65,17 @@ public function getCorporationLedgers(int $corporation_id, bool $get = true)
public function getCorporationLedger(int $corporation_id, int $year, int $month, bool $get = true)
{

$ledger = CharacterMining::select('character_minings.character_id', 'year', 'month', 'type_id', 'quantity', 'date')
$ledger = CharacterMining::select('character_minings.character_id', 'year', 'month', DB::raw('SUM(quantity) as quantity'), DB::raw('SUM(quantity * volume) as volumes'), DB::raw('SUM(quantity * adjusted_price) as amounts'))
->join('corporation_member_trackings', 'corporation_member_trackings.character_id', 'character_minings.character_id')
->join('invTypes', 'invTypes.typeID', 'character_minings.type_id')
->leftJoin('historical_prices', function ($join) {
$join->on('historical_prices.type_id', '=', 'character_minings.type_id')
->on('historical_prices.date', '=', 'character_minings.date');
})
->where('corporation_id', $corporation_id)
->where('year', $year)
->where('month', $month);
->where('month', $month)
->groupBy('character_id', 'year', 'month');

if (! $get)
return $ledger;
Expand Down

0 comments on commit 817483c

Please sign in to comment.