mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update InstanceService, improve unlisted/banned network post filtering
This commit is contained in:
parent
87cff47c03
commit
a0da6ec39a
3 changed files with 35 additions and 3 deletions
|
@ -7,13 +7,14 @@ use App\Instance;
|
|||
|
||||
class InstanceService
|
||||
{
|
||||
const CACHE_KEY_BY_DOMAIN = 'pf:services:instance:by_domain:';
|
||||
const CACHE_KEY_BANNED_DOMAINS = 'instances:banned:domains';
|
||||
const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains';
|
||||
const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains';
|
||||
|
||||
public static function getByDomain($domain)
|
||||
{
|
||||
return Cache::remember('pf:services:instance:by_domain:'.$domain, 3600, function() use($domain) {
|
||||
return Cache::remember(self::CACHE_KEY_BY_DOMAIN.$domain, 3600, function() use($domain) {
|
||||
return Instance::whereDomain($domain)->first();
|
||||
});
|
||||
}
|
||||
|
@ -50,4 +51,17 @@ class InstanceService
|
|||
return $instance->software;
|
||||
});
|
||||
}
|
||||
|
||||
public static function refresh()
|
||||
{
|
||||
Cache::forget(self::CACHE_KEY_BANNED_DOMAINS);
|
||||
Cache::forget(self::CACHE_KEY_UNLISTED_DOMAINS);
|
||||
Cache::forget(self::CACHE_KEY_NSFW_DOMAINS);
|
||||
|
||||
self::getBannedDomains();
|
||||
self::getUnlistedDomains();
|
||||
self::getNsfwDomains();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,11 @@ class NetworkTimelineService
|
|||
if(self::count() == 0 || $force == true) {
|
||||
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
|
||||
Redis::del(self::CACHE_KEY);
|
||||
$filteredDomains = collect(InstanceService::getBannedDomains())
|
||||
->merge(InstanceService::getUnlistedDomains())
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
$ids = Status::whereNotNull('uri')
|
||||
->whereScope('public')
|
||||
->when($hideNsfw, function($q, $hideNsfw) {
|
||||
|
@ -88,7 +93,13 @@ class NetworkTimelineService
|
|||
->where('created_at', '>', now()->subHours(config('instance.timeline.network.max_hours_old')))
|
||||
->orderByDesc('created_at')
|
||||
->limit($limit)
|
||||
->pluck('id');
|
||||
->pluck('uri', 'id');
|
||||
$ids = $ids->filter(function($k, $v) use($filteredDomains) {
|
||||
$domain = parse_url($k, PHP_URL_HOST);
|
||||
return !in_array($domain, $filteredDomains);
|
||||
})->map(function($k, $v) {
|
||||
return $v;
|
||||
})->flatten();
|
||||
foreach($ids as $id) {
|
||||
self::add($id);
|
||||
}
|
||||
|
|
|
@ -510,7 +510,14 @@ class Helpers {
|
|||
$status->created_at->gt(now()->subHours(config('instance.timeline.network.max_hours_old'))) &&
|
||||
(config('instance.hide_nsfw_on_public_feeds') == true ? $status->is_nsfw == false : true)
|
||||
) {
|
||||
NetworkTimelineService::add($status->id);
|
||||
$filteredDomains = collect(InstanceService::getBannedDomains())
|
||||
->merge(InstanceService::getUnlistedDomains())
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
if(!in_array($urlDomain, $filteredDomains)) {
|
||||
NetworkTimelineService::add($status->id);
|
||||
}
|
||||
}
|
||||
|
||||
IncrementPostCount::dispatch($pid)->onQueue('low');
|
||||
|
|
Loading…
Reference in a new issue