Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient squad updates #2 #686

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/Commands/Seat/Filters/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Commands\Seat\Filters;

use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Seat\Web\Jobs\UpdateCharacterFilters;

class Update extends Command
{
use DispatchesJobs;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'seat:filters:update';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Runs squad and character scheduling rule updates';

/**
* Run the command.
*
* @return void
*/
public function handle(): void
{
UpdateCharacterFilters::dispatch()->onQueue('high');
$this->line('Scheduled character filter updates for all characters!');
}
}
55 changes: 55 additions & 0 deletions src/Jobs/UpdateCharacterFilters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Seat\Eveapi\Models\Character\CharacterInfo;
use Seat\Web\Events\CharacterFilterDataUpdate;

class UpdateCharacterFilters implements ShouldQueue
{
use Queueable, InteractsWithQueue, Dispatchable;

public function tags()
{
return ['web', 'filters'];
}

/**
* Go over all character and trigger a character filter update.
*
* @return void
*/
public function handle()
{
// without chunking, we can run out of memory on large installs
CharacterInfo::chunk(200, function ($characters) {
foreach ($characters as $character){
event(new CharacterFilterDataUpdate($character));
}
});
}
}
34 changes: 34 additions & 0 deletions src/Listeners/CharacterBatchProcessed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Listeners;

use Seat\Eveapi\Events\CharacterBatchProcessed as BatchEvent;
use Seat\Web\Events\CharacterFilterDataUpdate;

class CharacterBatchProcessed
{
public static function handle(BatchEvent $event)
{
event(new CharacterFilterDataUpdate($event->character));
}
}
64 changes: 0 additions & 64 deletions src/Observers/CharacterAffiliationObserver.php

This file was deleted.

71 changes: 0 additions & 71 deletions src/Observers/CharacterAssetObserver.php

This file was deleted.

34 changes: 1 addition & 33 deletions src/Observers/CharacterRoleObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@
namespace Seat\Web\Observers;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Seat\Eveapi\Bus\Corporation;
use Seat\Eveapi\Models\Character\CharacterInfo;
use Seat\Eveapi\Models\Character\CharacterRole;
use Seat\Eveapi\Models\RefreshToken;
use Seat\Web\Models\User;

/**
* Class CharacterRoleObserver.
*
* @package Seat\Web\Observers
*/
class CharacterRoleObserver extends AbstractCharacterFilterObserver
class CharacterRoleObserver
{
/**
* @param \Seat\Eveapi\Models\Character\CharacterRole $role
*/
public function created(CharacterRole $role)
{
$this->fireCharacterFilterEvent($role);

// in case the created role is not a Director role, ignore
if ($role->role != 'Director')
return;
Expand All @@ -62,31 +57,4 @@ public function created(CharacterRole $role)
logger()->error($e->getMessage());
}
}

/**
* @param \Seat\Eveapi\Models\Character\CharacterRole $role
*/
public function updated(CharacterRole $role)
{
$this->fireCharacterFilterEvent($role);
}

/**
* @param \Seat\Eveapi\Models\Character\CharacterRole $role
*/
public function deleted(CharacterRole $role)
{
$this->fireCharacterFilterEvent($role);
}

/**
* Return the User owning the model which fired the catch event.
*
* @param \Illuminate\Database\Eloquent\Model $fired_model The model which fired the catch event
* @return ?CharacterInfo The character that is affected by this update
*/
protected function findRelatedCharacter(Model $fired_model): ?CharacterInfo
{
return $fired_model->character;
}
}
Loading
Loading