mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
799 B
PHTML
46 lines
799 B
PHTML
6 years ago
|
<?php
|
||
|
|
||
|
namespace App\Services;
|
||
|
|
||
|
use Redis;
|
||
|
use App\Profile;
|
||
|
|
||
|
class SuggestionService {
|
||
|
|
||
|
const CACHE_KEY = 'pf:services:suggestion:ids';
|
||
|
|
||
|
public static function get($start = 0, $stop = -1)
|
||
|
{
|
||
|
return Redis::zrange(self::CACHE_KEY, $start, $stop);
|
||
|
}
|
||
|
|
||
|
public static function set($val)
|
||
|
{
|
||
|
return Redis::zadd(self::CACHE_KEY, 1, $val);
|
||
|
}
|
||
|
|
||
|
public static function del($val)
|
||
|
{
|
||
|
return Redis::zrem(self::CACHE_KEY, $val);
|
||
|
}
|
||
|
|
||
|
public static function add($val)
|
||
|
{
|
||
|
return self::set($val);
|
||
|
}
|
||
|
|
||
|
public static function rem($val)
|
||
|
{
|
||
|
return self::del($val);
|
||
|
}
|
||
|
|
||
|
public static function warmCache()
|
||
|
{
|
||
|
if(Redis::zcount(self::CACHE_KEY, '-inf', '+inf') == 0) {
|
||
|
$ids = Profile::whereNull('domain')->whereIsSuggestable(true)->pluck('id');
|
||
|
foreach($ids as $id) {
|
||
|
self::set($id);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|