pixelfed/app/Listeners/AuthLogin.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2018-07-23 17:29:20 +00:00
<?php
2018-09-16 00:36:04 +00:00
namespace App\Listeners;
2018-07-23 17:29:20 +00:00
2018-11-27 08:54:10 +00:00
use DB, Cache;
use App\{
Follower,
User,
UserFilter,
UserSetting
};
2018-09-16 00:36:04 +00:00
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
2018-07-23 17:29:20 +00:00
2018-09-16 00:36:04 +00:00
class AuthLogin
2018-07-23 17:29:20 +00:00
{
2018-09-16 00:36:04 +00:00
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
2018-07-23 17:29:20 +00:00
{
2018-09-16 00:36:04 +00:00
$user = $event->user;
2018-08-28 03:07:36 +00:00
if (empty($user->settings)) {
2018-10-24 18:41:14 +00:00
DB::transaction(function() use($user) {
UserSetting::firstOrCreate([
'user_id' => $user->id
]);
});
2018-07-23 17:29:20 +00:00
}
2018-11-27 08:54:10 +00:00
$this->warmCache($user);
}
public function warmCache($user)
{
$pid = $user->profile->id;
Cache::remember('feature:discover:following:'.$pid, 10080, function() use ($pid) {
return Follower::whereProfileId($pid)->pluck('following_id')->toArray();
});
Cache::remember("user:filter:list:$pid", 10080, function() use($pid) {
return UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray();
});
2018-07-23 17:29:20 +00:00
}
}