Why?
user.last_login gets updated every api request.
How?
Add a new parameter to allow disabling the listener
agreed -- it's an expensive query (because it's an update, not simply a read like getting the user). Especially in API calls.
One way to disable it is to override the method in User.php
// hack to disable lastLogin update
public function setLastLogin(\DateTime $time = null) {}
You can try to create a compiler pass which removes the service / event from the container
https://symfony.com/doc/current/service_container/compiler_passes.html
You can change fos_user.security.interactive_login_listener.class class to your own implementation:
parameters:
fos_user.security.interactive_login_listener.class: ApiBundle\EventListener\LastLoginListener
And then implement own logic (like "do nothing"):
<?php
namespace ApiBundle\EventListener;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use FOS\UserBundle\EventListener\LastLoginListener as BaseLastLoginListener;
class LastLoginListener extends BaseLastLoginListener
{
/**
* @param InteractiveLoginEvent $event
*/
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) {}
}
@asamek thanks. works like a charm!
Most helpful comment
You can change
fos_user.security.interactive_login_listener.classclass to your own implementation:And then implement own logic (like "do nothing"):