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

love:recount error following custom migration #137

Closed
vesper8 opened this issue Feb 3, 2020 · 8 comments · Fixed by #148
Closed

love:recount error following custom migration #137

vesper8 opened this issue Feb 3, 2020 · 8 comments · Fixed by #148
Labels
Milestone

Comments

@vesper8
Copy link

vesper8 commented Feb 3, 2020

I am performing a migration from cybercog/laravel-likeable v3 straight to laravel-love v8

I found it much easier to do a custom migration then to perform each step of the Upgrade guide manually.

I have a rather simple scenario where my only reacters/reactants are my User model. Users can like other users and that's it.. pretty simple.

I added love_reactant_id and love_reactor_id to my user model, I populated the love_reacters and love_reacants tables, I populated the love_reaction_types model and finally I converted the old likes table to the love_reactions table, making sure to use the correct reacter/reactant id

All this is working great.

My problem is that now both the love_reactant_reaction_totals and love_reactant_reaction_counters tables are empty

I thought this wouldn't be a problem since I figured the love:recount command would recalculate/repopulate both of those tables.. but it seems maybe I was wrong to assume this.

It seems like the love:recount command actually depends on the love_reactant_reaction_totals data in order to recalculate the love_reactant_reaction_counters table

But then isn't there a way to recalculate the love_reactant_reaction_totals table?

Right now I am getting this error when trying to run love:recount: Symfony\Component\Debug\Exception\FatalThrowableError : Call to undefined method Cog\Laravel\Love\Reactant\ReactionTotal\Models\NullReactionTotal::update()

I thought this might be the same problem described in #80 but it seems not, I have tried using the sync queue as well as making sure my queues are active.. and I think the problem is that my love_reactant_reaction_totals is empty

Can you confirm? Is there a way to recalculate that table?

Thank you

@vesper8
Copy link
Author

vesper8 commented Feb 3, 2020

Alternatively, I could generate those two tables by iterating over the old likes table and running the reactTo()method, this works wonderfully except that I lose the created_at/updated_at which is no good since I do want to keep this data to know when the likes were performed.

If you could add the possibility of passing an optional 4th parameter to pass the date to the reactTo method that would be nice.. in the meantime if it's possible to recalculate the two statistics table that would also solve my issue

@antonkomarev
Copy link
Member

antonkomarev commented Feb 3, 2020

Hi @vesper8!

If reactions are working I suppose that it's just typo here, but re-check that column in User model called love_reacter_id and not love_reactor_id.

I've refreshed implementation of counters in terms of #119 in my mind today morning, and saw that there are issues in it. It definitely need to be refactored.

Related to this issue - the problem in recounting command that it doesn't create missing counters. So if they are not exists - it wouldn't work. All we need to do - add counter creation command if we've got NullReactionCounter and add total creation if we've got NullReactionTotal.

@antonkomarev
Copy link
Member

antonkomarev commented Feb 9, 2020

This bug has been fixed in PR #148

@antonkomarev
Copy link
Member

antonkomarev commented Feb 9, 2020

@vesper8 You could try fix in the master branch:

composer require cybercog/laravel-love:dev-master

It will be released as v8.3 on the next week.

@vesper8
Copy link
Author

vesper8 commented Feb 16, 2020

Looking forward to 8.3 @antonkomarev : ) is it due any day now?

@antonkomarev
Copy link
Member

@vesper8 working on it right now ;)

@vesper8
Copy link
Author

vesper8 commented Feb 17, 2020

Great @antonkomarev ! I've tested it and it works very well, much better and seemingly faster than before.

I was still unable to run php artisan love:recount from the CLI as I immediately ran into an "Out of Allowed Memory exception"

I worked around it by creating a custom command that executes the following:

    public function handle()
    {
        ini_set('max_execution_time', 9999);
        ini_set('memory_limit', '2048M');

        $users = User::withTrashed()->whereNotNull('love_reactant_id')->orderBy('id')->get();

        $this->info(sprintf('Found %d users for recounting', $users->count()));
        
        $reactionTypes = ReactionType::all();

        foreach ($reactionTypes as $reactionType) {
            foreach ($users as $user) {
                $reactant = $user->getLoveReactant();
                RebuildReactionAggregatesJob::dispatch($reactant, $reactionType)
                ->onConnection('sync');
            }
        }
    }

The two ini_set are key to this working on the command line. I do this with many of my more memory-intensive jobs.

Happy to report I was also able to get the same results by running this from the command line:

php -d memory_limit=-1 artisan love:recount

@antonkomarev
Copy link
Member

Thanks for sharing it, @vesper8! I've added this hint to the documentation:
https://laravel-love.readme.io/docs/recount-statistics#section-out-of-allowed-memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants