-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: best answer counts not updated on post/discussion delete (#87)
* chore: create tests to highlight the defect (failing) * fix: listen for deletion, reduce ba count * Apply fixes from StyleCI * chore: enable backend testing * feat: provide cli command to re-sync all user ba counts * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
192b198
commit 022f775
Showing
17 changed files
with
619 additions
and
40 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ js/dist | |
js/node_modules | ||
vendor | ||
composer.lock | ||
.phpunit.result.cache |
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
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
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/best-answer. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\BestAnswer\Console; | ||
|
||
use Flarum\User\User; | ||
use FoF\BestAnswer\BestAnswerRepository; | ||
use Illuminate\Console\Command; | ||
|
||
class UpdateBestAnswerCounts extends Command | ||
{ | ||
/** | ||
* @var BestAnswerRepository | ||
*/ | ||
public $bestAnswers; | ||
|
||
public function __construct(BestAnswerRepository $bestAnswers) | ||
{ | ||
parent::__construct(); | ||
$this->bestAnswers = $bestAnswers; | ||
} | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $signature = 'fof:best-answer:update-counts'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Update best answer counts for all users'; | ||
|
||
public function handle() | ||
{ | ||
$this->info('Updating best answer counts...'); | ||
|
||
$userCount = User::count(); | ||
|
||
$bar = $this->output->createProgressBar($userCount); | ||
|
||
User::query()->chunkById(100, function ($users) use ($bar) { | ||
foreach ($users as $user) { | ||
$user->best_answer_count = $this->bestAnswers->calculateBestAnswersForUser($user); | ||
$user->save(); | ||
|
||
$bar->advance(); | ||
} | ||
}); | ||
|
||
$bar->finish(); | ||
|
||
$this->info('Done!'); | ||
} | ||
} |
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
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
Empty file.
Oops, something went wrong.