|
@@ -3,26 +3,24 @@
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
use Cache;
|
|
use Cache;
|
|
|
|
+use App\UserFilter;
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
-use App\{
|
|
|
|
- Follower,
|
|
|
|
- Profile,
|
|
|
|
- UserFilter
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-class UserFilterService {
|
|
|
|
-
|
|
|
|
|
|
+class UserFilterService
|
|
|
|
+{
|
|
const USER_MUTES_KEY = 'pf:services:mutes:ids:';
|
|
const USER_MUTES_KEY = 'pf:services:mutes:ids:';
|
|
const USER_BLOCKS_KEY = 'pf:services:blocks:ids:';
|
|
const USER_BLOCKS_KEY = 'pf:services:blocks:ids:';
|
|
|
|
|
|
- public static function mutes(int $profile_id) : array
|
|
|
|
|
|
+ public static function mutes(int $profile_id)
|
|
{
|
|
{
|
|
$key = self::USER_MUTES_KEY . $profile_id;
|
|
$key = self::USER_MUTES_KEY . $profile_id;
|
|
- $cached = Redis::zrevrange($key, 0, -1);
|
|
|
|
- if($cached) {
|
|
|
|
- return $cached;
|
|
|
|
|
|
+ $warm = Cache::has($key . ':cached');
|
|
|
|
+ if($warm) {
|
|
|
|
+ return Redis::zrevrange($key, 0, -1) ?? [];
|
|
} else {
|
|
} else {
|
|
|
|
+ if(Redis::zrevrange($key, 0, -1)) {
|
|
|
|
+ return Redis::zrevrange($key, 0, -1);
|
|
|
|
+ }
|
|
$ids = UserFilter::whereFilterType('mute')
|
|
$ids = UserFilter::whereFilterType('mute')
|
|
->whereUserId($profile_id)
|
|
->whereUserId($profile_id)
|
|
->pluck('filterable_id')
|
|
->pluck('filterable_id')
|
|
@@ -30,29 +28,34 @@ class UserFilterService {
|
|
foreach ($ids as $muted_id) {
|
|
foreach ($ids as $muted_id) {
|
|
Redis::zadd($key, (int) $muted_id, (int) $muted_id);
|
|
Redis::zadd($key, (int) $muted_id, (int) $muted_id);
|
|
}
|
|
}
|
|
|
|
+ Cache::set($key . ':cached', 1, 7776000);
|
|
return $ids;
|
|
return $ids;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function blocks(int $profile_id) : array
|
|
|
|
|
|
+ public static function blocks(int $profile_id)
|
|
{
|
|
{
|
|
$key = self::USER_BLOCKS_KEY . $profile_id;
|
|
$key = self::USER_BLOCKS_KEY . $profile_id;
|
|
- $cached = Redis::zrevrange($key, 0, -1);
|
|
|
|
- if($cached) {
|
|
|
|
- return $cached;
|
|
|
|
|
|
+ $warm = Cache::has($key . ':cached');
|
|
|
|
+ if($warm) {
|
|
|
|
+ return Redis::zrevrange($key, 0, -1) ?? [];
|
|
} else {
|
|
} else {
|
|
|
|
+ if(Redis::zrevrange($key, 0, -1)) {
|
|
|
|
+ return Redis::zrevrange($key, 0, -1);
|
|
|
|
+ }
|
|
$ids = UserFilter::whereFilterType('block')
|
|
$ids = UserFilter::whereFilterType('block')
|
|
->whereUserId($profile_id)
|
|
->whereUserId($profile_id)
|
|
->pluck('filterable_id')
|
|
->pluck('filterable_id')
|
|
->toArray();
|
|
->toArray();
|
|
foreach ($ids as $blocked_id) {
|
|
foreach ($ids as $blocked_id) {
|
|
- Redis::zadd($key, $blocked_id, $blocked_id);
|
|
|
|
|
|
+ Redis::zadd($key, (int) $blocked_id, (int) $blocked_id);
|
|
}
|
|
}
|
|
|
|
+ Cache::set($key . ':cached', 1, 7776000);
|
|
return $ids;
|
|
return $ids;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static function filters(int $profile_id) : array
|
|
|
|
|
|
+ public static function filters(int $profile_id)
|
|
{
|
|
{
|
|
return array_unique(array_merge(self::mutes($profile_id), self::blocks($profile_id)));
|
|
return array_unique(array_merge(self::mutes($profile_id), self::blocks($profile_id)));
|
|
}
|
|
}
|