Closed volkv closed 4 years ago
Hi @volkv we're always open to the new ideas! I think we could add getConnection
method and by default it will return null
that means it will use default connection from the .env file. But it might be modified by user then.
@volkv if you are making calls with JS can't you send this changes to frontend with websockets? What is the reason to have real data in response when you just could add +1 to reaction if 201 response was returned?
There are 2 implementations #141 #142 have been done so far by @volkv. I'm thinking about another one approach. Will try to describe it tomorrow evening. In short - we could encapsulate all logic from Listener's handle method in separate job. Then Listener will become synchronous and Job will be queued.
if you are making calls with JS can't you send this changes to frontend with websockets? What is the reason to have real data in response when you just could add +1 to reaction if 201 response was returned?
@antonkomarev there could be non-trivial logic after user reacted to something, which will affect the result of the overall reaction count. For example, when user adds +1 to a reaction it causes other reaction to subtract -1.
To replicate this on both frontend and backend is kind of a pain.
Websockets can help solve this problem, but we don't use them at all in our project anywhere else, so we were looking for an AJAX solution.
@volkv @alvinwhite I've found a solution which I hope will fit all the requirements and will be easy to use. https://github.com/cybercog/laravel-love/issues/145#issuecomment-583730266
You will need to opt-out package discovery:
"extra": {
"laravel": {
"dont-discover": [
"cybercog/laravel-love"
]
}
},
Register only core LoveServiceProvider
provider in your application's AppServiceProvider
:
$this->app->register(\Cog\Laravel\Love\LoveServiceProvider::class);
Finally, register any custom event listeners in your EventServiceProvider
. To not reinvent the wheel you could just make a copy of stock Love's listeners and dispatch jobs introduced in #146 on sync
connection:
IncrementReactionAggregatesJob::dispatch()->onConnection('sync');
First part is ready to be merged: #146
Last part is ready to be merged right after testing in real application: #147
New solution is working for me! You could try the master branch:
composer require cybercog/laravel-love:dev-master
It will be released as part of Laravel Love v8.3 soon.
Hi @antonkomarev You've hardcoded Queue behavior. I can make a PR with another non-queued listeners and a new config option. Is it ok? Or there is a better way to do it? Because I want to use queues globally, but reactions should be sync to get changes in JS response. Thanks