From 4d95d2cb7fabc7554a44ae5e14aa6b82817cfa06 Mon Sep 17 00:00:00 2001 From: Daniel Supernault <877217+dansup@users.noreply.github.com> Date: Mon, 12 Sep 2022 21:26:22 -0600 Subject: [PATCH] Add ProfileStatusService --- app/Services/ProfileStatusService.php | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 app/Services/ProfileStatusService.php diff --git a/app/Services/ProfileStatusService.php b/app/Services/ProfileStatusService.php new file mode 100644 index 000000000..907530dbc --- /dev/null +++ b/app/Services/ProfileStatusService.php @@ -0,0 +1,66 @@ + self::FALLOFF_LIMIT) { + Redis::zpopmin(self::CACHE_KEY . $pid); + } + return Redis::zadd(self::CACHE_KEY . $pid, $sid, $sid); + } + + public static function delete($pid, $sid) + { + return Redis::zrem(self::CACHE_KEY . $pid, $sid); + } + + public static function coldFetch($pid) + { + Redis::del(self::CACHE_KEY . $pid); + $ids = DB::table('statuses') + ->select('id', 'profile_id', 'type', 'scope') + ->whereIn('type', ['photo', 'photo:album', 'video']) + ->whereIn('scope', ['public', 'unlisted']) + ->whereProfileId($pid) + ->orderByDesc('id') + ->limit(self::FALLOFF_LIMIT) + ->pluck('id') + ->toArray(); + + if($ids && count($ids)) { + foreach($ids as $id) { + self::add($pid, $id); + } + } + Redis::zadd(self::COLD_CHECK_KEY, $pid, $pid); + return $ids; + } +}