Description
In my application I have about 10k reacters and 25k reactants.
If my love_reactions table is completely empty, issuing the recount command still takes an incredibly long time.. almost 1 full minute. Same thing if my love_reactions table contains just a dozen or two reactions
I can only assume that the recount command is for some reason iterating over all reacters or reactants, or both.. but why would it do that? Isn't the source of truth in this case the love_reactions table? If the love reactions table is empty, then the recount should be incredibly fast?
On this note, is there a method for clearing all reactions from a specific reacter? Say I want to delete a reacter (a user) and I wants all of its reactions cleared from the tables. Currently I'm doing it like this:
\DB::connection('data')
->table('love_reactions')
->where('reacter_id', $user->getLoveReacter()->id)
->delete();
And then I'm issuing the recount.. which takes way too long IMO, specially if the above command just basically truncated the love_reactions table as it does in my test case
Lastly.. could you make it possible to call the command from a controller? Right now I'm doing this Artisan::call('love:recount');
But I find that doing this kind of call from a controller is a bit hacky. At least if I could dispatch the job from a controller. But the problem is you've added all the logic in the command class, instead of creating a command that dispatches a job and putting the logic in the job class, so it may be dispatched from other places. That's how I usually do it in my projects.. separating the commands and the jobs.. specially if a lot of processing/logic is involved such as in this case
Food for thought.. thanks for consideration