1
0
Fork 0
pixelfed/app/Services/SuggestionService.php

57 lines
1011 B
PHP
Raw Normal View History

2019-04-28 22:38:23 +00:00
<?php
namespace App\Services;
2019-12-11 06:04:03 +00:00
use Illuminate\Support\Facades\Redis;
2019-04-28 22:38:23 +00:00
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);
}
2019-04-29 03:04:42 +00:00
public static function count()
{
return Redis::zcount(self::CACHE_KEY, '-inf', '+inf');
}
2019-04-28 23:43:55 +00:00
public static function warmCache($force = false)
2019-04-28 22:38:23 +00:00
{
2019-04-29 03:04:42 +00:00
if(self::count() == 0 || $force == true) {
2019-04-28 23:03:35 +00:00
$ids = Profile::whereNull('domain')
->whereIsSuggestable(true)
->whereIsPrivate(false)
2019-05-13 04:19:44 +00:00
->whereHas('statuses')
2019-04-28 23:03:35 +00:00
->pluck('id');
2019-04-28 22:38:23 +00:00
foreach($ids as $id) {
self::set($id);
}
2019-04-29 03:04:42 +00:00
return 1;
2019-04-28 22:38:23 +00:00
}
2019-04-29 03:04:42 +00:00
return 0;
2019-04-28 22:38:23 +00:00
}
}