laravel-authentication-log icon indicating copy to clipboard operation
laravel-authentication-log copied to clipboard

Optimize Other Devices Logout Listener

Open nessimabadi opened this issue 3 years ago • 2 comments

Currently, when logging out of other devices, the listener updates every record for the given user, on a large dataset this can be hundreds of queries. By limiting the scope of the records to only the ones that are not logged out, the number of queries is reduced to a minimum amount.

nessimabadi avatar May 16 '22 15:05 nessimabadi

This can be further optimized by changing the flow to a single update statement. If it is preferred to do it this way I could change the PR.

$user->authentications()
    ->whereLoginSuccessful(true)
    ->whereNull('logout_at')
    ->where('id', '!=', $authenticationLog->id)
    ->update([
        'cleared_by_user' => true,
        'logout_at' => now(),
    ]);

nessimabadi avatar May 16 '22 15:05 nessimabadi

@rappasoft Do you need me to change or add something in order for this to be merged to the main branch.

nessimabadi avatar Jul 05 '22 20:07 nessimabadi

HI @rappasoft

Is there any update on this PR? need any changes?

Thanks for all the work

nessimabadi avatar Jan 04 '23 19:01 nessimabadi