Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: batch avatar generation for larger user numbers (#4)
* fix: batch avatar generation for larger user numbers * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
- Loading branch information
1 parent
e01a7f7
commit 60004b0
Showing
3 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of ianm/boring-avatars. | ||
* | ||
* Copyright (c) 2024 IanM. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace IanM\BoringAvatars\Job; | ||
|
||
use Flarum\Database\Eloquent\Collection; | ||
use Flarum\Queue\AbstractJob; | ||
use IanM\BoringAvatars\BoringAvatar; | ||
use IanM\BoringAvatars\Command\GenerateAvatar; | ||
use Illuminate\Contracts\Bus\Dispatcher; | ||
|
||
class AvatarGenerationBatch extends AbstractJob | ||
{ | ||
public function __construct( | ||
protected Collection $users, | ||
protected bool $force = false | ||
) { | ||
} | ||
|
||
public function handle(Dispatcher $bus): void | ||
{ | ||
$this->users->each(function ($user) use ($bus) { | ||
if ($this->force || $user->user_svg === null) { | ||
if ($user->user_svg !== null) { | ||
$user->user_svg = null; | ||
$user->save(); | ||
} | ||
$bus->dispatch(new GenerateAvatar($user, BoringAvatar::$defaultGenerationSize, BoringAvatar::$defaultSquareAvatar)); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters