Closed Ajay-Bacancy closed 1 year ago
Yeah it seems like you should use low-level API to fit your needs.
$reacter = $user->getLoveReacter();
$reactant = $post->getLoveReactant();
$userReactionsOnPost = $reacter->reactions()->where('reactant_id', $reactant->getId())->get();
@Ajay-Bacancy here is an issue related to your question about stop queue of reaction counter:
I wrote a new page in documentation with example how to make jobs queue sync: https://laravel-love.readme.io/docs/custom-jobs-dispatching
Ohhh @antonkomarev I have done the same thing.
Maybe in enhancement of we can do something like that where we can pass the reactant in getReactions facade like this
$reacterFacade->getReactions($reactant)
to get reactors reaction on specific reactant.
But anyways I'm closing the issue you can lable it as question and Thank you so much for the custom job dispatching guide really appreciated. Also very nice library for reaction. I have integrated few days back. Thanks Buddy 🤗
Looks good! Thanks for sharing! I will think about your proposal
@Ajay-Bacancy FYI this code block may work pretty slow in cases when reacter has many reactions, on each new reaction it will become slower:
$userreactions = $reacterFacade->getReactions()->where('reactant_id', $reactant->id)->values()->pluck('reaction_type_id');
Here breakdown with explanation:
$allUserRactions = $reacterFacade->getReactions(); // Here you collecting all the reactions of the user from the database
$filteredUserReactions = $allUserReactions->where('reactant_id', $reactant->id); // We are iterate through the collection and filter out items
$reactionTypeIds = $filteredUserReactions->values()->pluck('reaction_type_id');
As you can see, filtering operation is doing on the PHP side, not on database side, and this may be critical over time.
Instead of getting reactions using ReacterFacade use low-level API and get Reacter model.
$reacter = $user->getLoveReacter();
$reactant = $post->getLoveReactant();
$userReactionsOnPost = $reacter->reactions()->where('reactant_id', $reactant->getId())->pluck('reaction_type_id');
Then reactions()
method will return Query builder, not all the reactions collection, and where
method will do the filtering on the database side.
@antonkomarev yeh got your point. Thank you so much buddy 😌❤️
@Ajay-Bacancy I've created discussion how to implement this feature on high-level API. Will be glad to receive a feedback there:
And the first proof of concept:
@Ajay-Bacancy I've introduced new method to fetch concrete user reactions. It's breaking change since API has been changed. Will be added in next major version release.
I wrote a new page in documentation with example how to make jobs queue sync: https://laravel-love.readme.io/docs/custom-jobs-dispatching
Hey @antonkomarev I have one doubt regarding custom job dispatching.
IncrementReactionAggregatesJob::dispatch()->onConnection('sync');
DecrementReactionAggregatesJob::dispatch()->onConnection('sync');
required instance of $reactant, $reaction
I'm doing it this way.
if ($isNotReacted) {
$reacterFacade->reactTo($post, $requestData['reaction_type'], 1.0);
$reaction = $reacterFacade->getReactions()->last();
IncrementReactionAggregatesJob::dispatch($reactant, $reaction)->onConnection('sync');
} else {
$reacterFacade->unreactTo($post, $requestData['reaction_type']);
DecrementReactionAggregatesJob::dispatch($reactant)->onConnection('sync');
}
getting all reaction and passing last added reaction. This will works fine with Increment job but how do I pass reaction instance in decrement job?
One of the solutions: use events and write your own event listener.
Event::listen(
ReactionHasBeenAdded::class,
IncrementAggregates::class,
);
Here is my setup. for adding reaction on the post. Now I want like which reaction is added by the user on perticular post.
is giving all the reaction made by the user but I want to get reaction with perticular post. Also I want to get the name of the reaction but there is no relationship function is given with ReactionType with reacterFacade. I tried to debug the package but did not found anything so asking here.
Also How can I stop Queue of Reaction Counter And Reaction Total Count. [NOTE] I want to update data immediately.