Skip to content

Commit

Permalink
delete assets without list of asset ids (#391)
Browse files Browse the repository at this point in the history
* delete assets without list of asset ids

* styleci

* styleci
  • Loading branch information
recursivetree authored Feb 14, 2024
1 parent 2bc8395 commit 5440e66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
15 changes: 3 additions & 12 deletions src/Jobs/Assets/Character/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,13 @@ class Assets extends AbstractAuthCharacterJob
*/
protected $page = 1;

/**
* @var \Illuminate\Support\Collection
*/
protected $known_assets;

/**
* Assets constructor.
*
* @param \Seat\Eveapi\Models\RefreshToken $token
*/
public function __construct(RefreshToken $token)
{
$this->known_assets = collect();

parent::__construct($token);
}

Expand All @@ -93,6 +86,8 @@ public function handle(): void
{
parent::handle();

$start = now();

$structure_batch = new StructureBatch();

while (true) {
Expand All @@ -119,10 +114,6 @@ public function handle(): void
return $this->getCharacterId();
},
])->save();

// Update the list of known item_id's which should be
// excluded from the database cleanup later.
$this->known_assets->push($asset->item_id);
});

if (! $this->nextPage($response->getPagesCount()))
Expand All @@ -131,7 +122,7 @@ public function handle(): void

// Cleanup old assets
CharacterAsset::where('character_id', $this->getCharacterId())
->whereNotIn('item_id', $this->known_assets->flatten()->all())
->where('updated_at', '<', $start)
->delete();

// schedule jobs for structures
Expand Down
15 changes: 3 additions & 12 deletions src/Jobs/Assets/Corporation/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ class Assets extends AbstractAuthCorporationJob
*/
protected $page = 1;

/**
* @var \Illuminate\Support\Collection
*/
protected $known_assets;

/**
* Assets constructor.
*
Expand All @@ -83,8 +78,6 @@ class Assets extends AbstractAuthCorporationJob
*/
public function __construct(int $corporation_id, RefreshToken $token)
{
$this->known_assets = collect();

parent::__construct($corporation_id, $token);
}

Expand All @@ -99,6 +92,8 @@ public function handle()
{
parent::handle();

$start = now();

$structure_batch = new StructureBatch();

while (true) {
Expand Down Expand Up @@ -130,17 +125,13 @@ public function handle()
});
});

// Update the list of known item_id's which should be
// excluded from the database cleanup later.
$this->known_assets->push($assets->pluck('item_id')->flatten()->all());

if (! $this->nextPage($response->getPagesCount()))
break;
}

// Cleanup old assets
CorporationAsset::where('corporation_id', $this->getCorporationId())
->whereNotIn('item_id', $this->known_assets->flatten()->all())
->where('updated_at', '<', $start)
->delete();

// schedule jobs for structures
Expand Down

0 comments on commit 5440e66

Please sign in to comment.