Remove INSTANCE_NETWORK_TIMELINE_CACHED, always use Redis cache

Remove the config entry and all DB-query fallback branches for the
network/federated timeline. NetworkTimelineService (Redis) is now
the only code path.

- config/instance.php: remove 'cached' key from timeline.network
- ApiV1Controller: remove DB fallback in network timeline branch
- PublicApiController: remove entire DB fallback (~70 lines)
- Helpers.php: remove cached check before adding to NetworkTimelineService
- Diagnostics: remove INSTANCE_NETWORK_TIMELINE_CACHED row
pull/6584/head
Your Name 3 months ago
parent ec51672fe2
commit 247054b262

@ -3005,51 +3005,18 @@ class ApiV1Controller extends Controller
->values()
->toArray();
} elseif ($remote && ! $local) {
if (config('instance.timeline.network.cached')) {
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
if (NetworkTimelineService::count() == 0) {
NetworkTimelineService::warmCache(true, config('instance.timeline.network.cache_dropoff'));
}
});
if ($max) {
$feed = NetworkTimelineService::getRankedMaxId($max, $limit + 5);
} elseif ($min) {
$feed = NetworkTimelineService::getRankedMinId($min, $limit + 5);
} else {
$feed = NetworkTimelineService::get(0, $limit + 5);
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
if (NetworkTimelineService::count() == 0) {
NetworkTimelineService::warmCache(true, config('instance.timeline.network.cache_dropoff'));
}
} else {
$feed = Status::select(
'id',
'uri',
'type',
'scope',
'local',
'created_at',
'profile_id',
'in_reply_to_id',
'reblog_of_id'
)
->when($minOrMax, function ($q, $minOrMax) use ($min, $max) {
$dir = $min ? '>' : '<';
$id = $min ?? $max;
});
return $q->where('id', $dir, $id);
})
->whereNull(['in_reply_to_id', 'reblog_of_id'])
->when($hideNsfw, function ($q, $hideNsfw) {
return $q->where('is_nsfw', false);
})
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereLocal(false)
->whereScope('public')
->where('id', '>', $amin)
->orderByDesc('id')
->limit(($limit * 2))
->pluck('id')
->values()
->toArray();
if ($max) {
$feed = NetworkTimelineService::getRankedMaxId($max, $limit + 5);
} elseif ($min) {
$feed = NetworkTimelineService::getRankedMinId($min, $limit + 5);
} else {
$feed = NetworkTimelineService::get(0, $limit + 5);
}
} else {
if (config('instance.timeline.local.cached')) {

@ -531,103 +531,38 @@ class PublicApiController extends Controller
$filtered = $user ? UserFilterService::filters($user->profile_id) : [];
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
if (config('instance.timeline.network.cached') == false) {
if ($min || $max) {
$dir = $min ? '>' : '<';
$id = $min ?? $max;
$timeline = Status::select(
'id',
'uri',
'type',
'scope',
'created_at',
)
->where('id', $dir, $id)
->when($hideNsfw, function ($q, $hideNsfw) {
return $q->where('is_nsfw', false);
})
->whereNull(['in_reply_to_id', 'reblog_of_id'])
->whereNotIn('profile_id', $filtered)
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
->where('id', '>', $amin)
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->map(function ($s) use ($user) {
$status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
return $status;
});
$res = $timeline->toArray();
} else {
$timeline = Status::select(
'id',
'uri',
'type',
'scope',
'created_at',
)
->whereNull(['in_reply_to_id', 'reblog_of_id'])
->whereNotIn('profile_id', $filtered)
->when($hideNsfw, function ($q, $hideNsfw) {
return $q->where('is_nsfw', false);
})
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotNull('uri')
->whereScope('public')
->where('id', '>', $amin)
->orderBy('created_at', 'desc')
->limit($limit)
->get()
->map(function ($s) use ($user) {
$status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id);
return $status;
});
$res = $timeline->toArray();
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
if (NetworkTimelineService::count() == 0) {
NetworkTimelineService::warmCache(true, 400);
}
} else {
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function () {
if (NetworkTimelineService::count() == 0) {
NetworkTimelineService::warmCache(true, 400);
}
});
});
if ($max) {
$feed = NetworkTimelineService::getRankedMaxId($max, $limit);
} elseif ($min) {
$feed = NetworkTimelineService::getRankedMinId($min, $limit);
} else {
$feed = NetworkTimelineService::get(0, $limit);
}
if ($max) {
$feed = NetworkTimelineService::getRankedMaxId($max, $limit);
} elseif ($min) {
$feed = NetworkTimelineService::getRankedMinId($min, $limit);
} else {
$feed = NetworkTimelineService::get(0, $limit);
}
$res = collect($feed)
->take($limit)
->map(function ($k) use ($user) {
$status = StatusService::get($k);
if ($status && isset($status['account']) && $user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $k);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $k);
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
}
$res = collect($feed)
->take($limit)
->map(function ($k) use ($user) {
$status = StatusService::get($k);
if ($status && isset($status['account']) && $user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $k);
$status['reblogged'] = (bool) ReblogService::get($user->profile_id, $k);
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
}
return $status;
})
->filter(function ($s) use ($filtered) {
return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) == false;
})
->values()
->toArray();
}
return $status;
})
->filter(function ($s) use ($filtered) {
return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) == false;
})
->values()
->toArray();
return response()->json($res);
}

@ -698,9 +698,7 @@ class Helpers
*/
public static function handleStatusPostProcessing(Status $status, int $profileId, string $url): void
{
if (config('instance.timeline.network.cached') &&
self::isEligibleForNetwork($status)
) {
if (self::isEligibleForNetwork($status)) {
$urlDomain = parse_url($url, PHP_URL_HOST);
$filteredDomains = self::getFilteredDomains();

@ -35,7 +35,6 @@ return [
],
'network' => [
'cached' => env('PF_NETWORK_TIMELINE') ? env('INSTANCE_NETWORK_TIMELINE_CACHED', true) : false,
'cache_dropoff' => env('INSTANCE_NETWORK_TIMELINE_CACHE_DROPOFF', 10000),
'max_hours_old' => env('INSTANCE_NETWORK_TIMELINE_CACHE_MAX_HOUR_INGEST', 2160),
],

@ -523,11 +523,6 @@
<td><span>{{config_cache('instance.timeline.local.is_public') ? '✅ true' : '❌ false' }}</span></td>
</tr>
<tr>
<td><span class="badge badge-primary">INSTANCE</span></td>
<td><strong>INSTANCE_NETWORK_TIMELINE_CACHED</strong></td>
<td><span>{{config('instance.timeline.network.cached') }}</span></td>
</tr>
<tr>
<td><span class="badge badge-primary">INSTANCE</span></td>
<td><strong>INSTANCE_NETWORK_TIMELINE_CACHE_DROPOFF</strong></td>

Loading…
Cancel
Save