Skip to content

Commit

Permalink
fix: updated_at for Assets Jobs (#402)
Browse files Browse the repository at this point in the history
* Chunk and update_at updates for Assets Jobs

* Chunk and update_at updates for Assets Jobs
  • Loading branch information
tehraven authored May 20, 2024
1 parent a87bc79 commit 22bd98f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
36 changes: 20 additions & 16 deletions src/Jobs/Assets/Character/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,26 @@ public function handle(): void

$assets = collect($response->getBody());

$assets->each(function ($asset) use ($structure_batch) {

$model = CharacterAsset::firstOrNew([
'item_id' => $asset->item_id,
]);

//make sure that the location is loaded if it is in a station or citadel
if (in_array($asset->location_flag, StructureBatch::RESOLVABLE_LOCATION_FLAGS) && in_array($asset->location_type, StructureBatch::RESOLVABLE_LOCATION_TYPES)) {
$structure_batch->addStructure($asset->location_id);
}

AssetMapping::make($model, $asset, [
'character_id' => function () {
return $this->getCharacterId();
},
])->save();
$assets->chunk(1000)->each(function ($chunk) use ($structure_batch, $start) {

$chunk->each(function ($asset) use ($structure_batch, $start) {

$model = CharacterAsset::firstOrNew([
'item_id' => $asset->item_id,
]);

//make sure that the location is loaded if it is in a station or citadel
if (in_array($asset->location_flag, StructureBatch::RESOLVABLE_LOCATION_FLAGS) && in_array($asset->location_type, StructureBatch::RESOLVABLE_LOCATION_TYPES)) {
$structure_batch->addStructure($asset->location_id);
}

AssetMapping::make($model, $asset, [
'character_id' => function () {
return $this->getCharacterId();
},
'updated_at' => $start,
])->save();
});
});

if (! $this->nextPage($response->getPagesCount()))
Expand Down
5 changes: 3 additions & 2 deletions src/Jobs/Assets/Corporation/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public function handle()

$assets = collect($response->getBody());

$assets->chunk(1000)->each(function ($chunk) use ($structure_batch) {
$assets->chunk(1000)->each(function ($chunk) use ($structure_batch, $start) {

$chunk->each(function ($asset) use ($structure_batch) {
$chunk->each(function ($asset) use ($structure_batch, $start) {

$model = CorporationAsset::firstOrNew([
'item_id' => $asset->item_id,
Expand All @@ -121,6 +121,7 @@ public function handle()
'corporation_id' => function () {
return $this->getCorporationId();
},
'updated_at' => $start,
])->save();
});
});
Expand Down

0 comments on commit 22bd98f

Please sign in to comment.