diff --git a/app/Jobs/Commands/FetchRentalMoonLedgerJob.php b/app/Jobs/Commands/FetchRentalMoonLedgerJob.php index 91ff262a3..4a7ad6df4 100644 --- a/app/Jobs/Commands/FetchRentalMoonLedgerJob.php +++ b/app/Jobs/Commands/FetchRentalMoonLedgerJob.php @@ -59,6 +59,7 @@ class FetchRentalMoonLedgerJob implements ShouldQueue $lookup = new LookupHelper; $response = null; $structureInfo = null; + $entries = array(); //Get the configuration for the main site $config = config('esi'); @@ -105,21 +106,31 @@ class FetchRentalMoonLedgerJob implements ShouldQueue //Get the corporation information $corpInfo = $lookup->GetCorporationInfo($charInfo->corporation_id); - $newLedger = new RentalMoonLedger; - $newLedger->corporation_id = $corpId; - $newLedger->corporation_name = $corpName; - $newLedger->character_id = $ledger->character_id; - $newLedger->character_name = $charInfo->name; - $newLedger->observer_id = $observer->observer_id; - $newLedger->observer_name = $observerName; - $newLedger->type_id = $ledger->type_id; - $newLedger->ore = $ore; - $newLedger->quantity = $ledger->quantity; - $newLedger->recorded_corporation_id = $ledger->recorded_corporation_id; - $newLedger->recorded_corporation_name = $recordedCorpName; - $newLedger->last_updated = $ledger->last_updated; - $newLedger->save(); + $entries[] = [ + 'corporation_id' => $corpId, + 'corporation_name' => $corpName, + 'character_id' => $ledger->character_id, + 'character_name' => $charInfo->name, + 'observer_id' => $observer->observer_id, + 'observer_name' => $observerName, + 'type_id' => $ledger->type_id, + 'ore' => $ore, + 'quantity' => $ledger->quantity, + 'recorded_corporation_id' => $ledger->recorded_corporation_id, + 'recorded_corporation_name' => $recordedCorpName, + 'last_updated' => $ledger->last_updated, + 'created_at' => $ledger->last_updated . ' 23:59:59', + 'updated_at' => $ledger->last_updated . ' 23:59:59', + ]; } + + //Insert or ignore each of the records saved into the array through the foreach loop + RentalMoonLedger::insertOrIgnore($entries); + + Log::info( + 'FetchRentalMoonLedgerJob inserted up to ' .count($entires) . ' new ledger entries.' + ); + } } } diff --git a/app/Jobs/Commands/FetchRentalMoonObserversJob.php b/app/Jobs/Commands/FetchRentalMoonObserversJob.php index 8d03da282..fbe0e7d79 100644 --- a/app/Jobs/Commands/FetchRentalMoonObserversJob.php +++ b/app/Jobs/Commands/FetchRentalMoonObserversJob.php @@ -56,6 +56,7 @@ class FetchRentalMoonObserversJob implements ShouldQueue //Declare some variables $lookup = new LookupHelper; $esi = new Esi; + $obss = array(); //Get the configuration for the main site $config = config('esi'); @@ -83,21 +84,14 @@ class FetchRentalMoonObserversJob implements ShouldQueue //Run through the mining observers, and add them to the database as needed foreach($responses as $observer) { - RentalMoonObserver::where(['observer_id' => $observer->observer_id])->count(); - //If the observer is not found, then add it to the database, otherwise we just need to update the last updated portion - if($count == 0) { - $obs = new RentalMoonObserver; - $obs->observer_id = $observer->observer_id; - $obs->observer_type = $observer->observer_type; - $obs->last_updated = $esi->DecodeDate($observer->last_updated); - $obs->save(); - } else { - RentalMoonObserver::where([ - 'observer_id' => $observer->observer_id, - ])->update([ - 'last_updated' => $esi->DecodeDate($observer->last_updated), - ]); - } + //Populate the array with the data, so we can do an insert or ignore after the foreach loop is completed. + $obss[] = [ + 'observer_id' => $observer->observer_id, + 'observer_type' => $observer->observer_type, + 'last_updated' => $esi->DecodeDate($observer->last_updated) + ]; } + + RentalMoonObserver::insertOrIgnore($obss); } } diff --git a/app/Jobs/Commands/MoonRentalInvoiceJob.php b/app/Jobs/Commands/MoonRentalInvoiceJob.php index 1176b2a22..d51c7393d 100644 --- a/app/Jobs/Commands/MoonRentalInvoiceJob.php +++ b/app/Jobs/Commands/MoonRentalInvoiceJob.php @@ -11,6 +11,19 @@ use Illuminate\Foundation\Bus\Dispatchable; class MoonRentalInvoiceJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * Timeout in seconds + * + * @var int + */ + public $timeout = 3600; + + /** + * Retries + * + * @var int + */ + public $retries = 3; /** * Create a new job instance. diff --git a/app/Models/Moon/RentalMoonObserver.php b/app/Models/Moon/RentalMoonObserver.php index 43eb0637b..cb7b0a625 100644 --- a/app/Models/Moon/RentalMoonObserver.php +++ b/app/Models/Moon/RentalMoonObserver.php @@ -23,4 +23,8 @@ class RentalMoonObserver extends Model 'observer_type', 'last_updated', ]; + + public function ledger() { + return $this->hasMany('App\Models\Moon\RentalMoonLedger', 'observer_id', 'observer_id'); + } }