[backend/core] Allow manual resetting of the home timeline heuristic
This commit is contained in:
parent
f19a414b27
commit
e4074dddbc
2 changed files with 10 additions and 2 deletions
|
@ -11,6 +11,8 @@ public static class QueryableTimelineExtensions
|
|||
// Determined empirically in 2023. Ask zotan for the spreadsheet if you're curious.
|
||||
private const int Cutoff = 250;
|
||||
|
||||
private const string Prefix = "following-query-heuristic";
|
||||
|
||||
public static IQueryable<Note> FilterByFollowingAndOwn(
|
||||
this IQueryable<Note> query, User user, DatabaseContext db, int heuristic
|
||||
)
|
||||
|
@ -27,10 +29,14 @@ public static class QueryableTimelineExtensions
|
|||
.Concat(new[] { user.Id })
|
||||
.Contains(note.UserId));
|
||||
|
||||
public static async Task ResetHeuristic(User user, CacheService cache)
|
||||
{
|
||||
await cache.ClearAsync($"{Prefix}:{user.Id}");
|
||||
}
|
||||
|
||||
public static async Task<int> GetHeuristic(User user, DatabaseContext db, CacheService cache)
|
||||
{
|
||||
return await cache.FetchValueAsync($"following-query-heuristic:{user.Id}",
|
||||
TimeSpan.FromHours(24), FetchHeuristic);
|
||||
return await cache.FetchValueAsync($"{Prefix}:{user.Id}", TimeSpan.FromHours(24), FetchHeuristic);
|
||||
|
||||
[SuppressMessage("ReSharper", "EntityFramework.UnsupportedServerSideFunctionCall")]
|
||||
async Task<int> FetchHeuristic()
|
||||
|
|
|
@ -119,6 +119,8 @@ public class CacheService([FromKeyedServices("cache")] DatabaseContext db)
|
|||
public async Task<T> FetchValueAsync<T>(string key, TimeSpan ttl, Func<T> fetcher, bool renew = false)
|
||||
where T : struct => await FetchValueAsync(key, ttl, () => Task.FromResult(fetcher()), renew);
|
||||
|
||||
public async Task ClearAsync(string key) => await db.CacheStore.Where(p => p.Key == key).ExecuteDeleteAsync();
|
||||
|
||||
private async Task<string?> GetValueAsync(string key)
|
||||
{
|
||||
return await db.CacheStore
|
||||
|
|
Loading…
Add table
Reference in a new issue