[backend/core] Revert Task.ContinueWithResult naming

This commit is contained in:
Laura Hausmann 2024-11-20 01:14:50 +01:00
parent a762a9201e
commit 51e4846635
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
8 changed files with 39 additions and 35 deletions

View file

@ -8,8 +8,11 @@ using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Controllers.Mastodon.Renderers;
public class NotificationRenderer(DatabaseContext db, NoteRenderer noteRenderer, UserRenderer userRenderer)
: IScopedService
public class NotificationRenderer(
DatabaseContext db,
NoteRenderer noteRenderer,
UserRenderer userRenderer
) : IScopedService
{
public async Task<NotificationEntity> RenderAsync(
Notification notification, User user, bool isPleroma, List<AccountEntity>? accounts = null,
@ -107,8 +110,8 @@ public class NotificationRenderer(DatabaseContext db, NoteRenderer noteRenderer,
Url = e.PublicUrl
})
.ToArrayAsync()
.ContinueWithResultAsync(res => res.DistinctBy(e => e.Name)
.ToDictionary(e => e.Name, e => e.Url));
.ContinueWithResult(res => res.DistinctBy(e => e.Name)
.ToDictionary(e => e.Name, e => e.Url));
return await notificationList
.Select(p => RenderAsync(p, user, isPleroma, accounts, notes, emojiUrls))

View file

@ -120,7 +120,7 @@ public sealed class WebSocketConnection(
.Select(p => p.UserId)
.Distinct()
.ToArrayAsync()
.ContinueWithResultAsync(p => p.ToHashSet());
.ContinueWithResult(p => p.ToHashSet());
}
public async Task HandleSocketMessageAsync(string payload)
@ -350,7 +350,7 @@ public sealed class WebSocketConnection(
.Where(p => p.UserList.UserId == Token.User.Id && p.UserList.HideFromHomeTl)
.Select(p => p.UserId)
.ToArrayAsync()
.ContinueWithResultAsync(p => p.ToHashSet());
.ContinueWithResult(p => p.ToHashSet());
}
catch (Exception e)
{

View file

@ -263,13 +263,13 @@ public class AdminController(
{
return await db.Relays
.ToArrayAsync()
.ContinueWithResultAsync(res => res.Select(p => new RelaySchemas.RelayResponse
{
Id = p.Id,
Inbox = p.Inbox,
Status = (RelaySchemas.RelayStatus)p.Status
})
.ToList());
.ContinueWithResult(res => res.Select(p => new RelaySchemas.RelayResponse
{
Id = p.Id,
Inbox = p.Inbox,
Status = (RelaySchemas.RelayStatus)p.Status
})
.ToList());
}
[HttpPost("relays")]

View file

@ -71,9 +71,7 @@ public class MigrationController(
aliasUri ??= await db.Users.IncludeCommonProperties()
.Where(p => p.Id == rq.UserId)
.FirstOrDefaultAsync()
.ContinueWithResultAsync(p => p is null
? null
: p.Uri ?? p.GetPublicUri(config.Value));
.ContinueWithResult(p => p is null ? null : p.Uri ?? p.GetPublicUri(config.Value));
}
if (aliasUri is null) throw GracefulException.NotFound("Alias user not found");

View file

@ -95,7 +95,7 @@ public class UserController(
.Paginate(pq, ControllerContext)
.PrecomputeVisibilities(localUser)
.ToListAsync()
.ContinueWithResultAsync(res => res.EnforceRenoteReplyVisibility());
.ContinueWithResult(res => res.EnforceRenoteReplyVisibility());
return await noteRenderer.RenderManyAsync(notes, localUser, Filter.FilterContext.Accounts);
}

View file

@ -1,5 +1,8 @@
using System.Diagnostics.CodeAnalysis;
namespace Iceshrimp.Backend.Core.Extensions;
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static class TaskExtensions
{
public static async Task SafeWaitAsync(this Task task, TimeSpan timeSpan)
@ -58,13 +61,13 @@ public static class TaskExtensions
return (await task).ToList();
}
public static async Task ContinueWithResultAsync(this Task task, Action continuation)
public static async Task ContinueWithResult(this Task task, Action continuation)
{
await task;
continuation();
}
public static async Task<TNewResult> ContinueWithResultAsync<TNewResult>(
public static async Task<TNewResult> ContinueWithResult<TNewResult>(
this Task task, Func<TNewResult> continuation
)
{
@ -72,25 +75,25 @@ public static class TaskExtensions
return continuation();
}
public static async Task ContinueWithResultAsync<TResult>(this Task<TResult> task, Action<TResult> continuation)
public static async Task ContinueWithResult<TResult>(this Task<TResult> task, Action<TResult> continuation)
{
continuation(await task);
}
public static async Task<TNewResult> ContinueWithResultAsync<TResult, TNewResult>(
public static async Task<TNewResult> ContinueWithResult<TResult, TNewResult>(
this Task<TResult> task, Func<TResult, TNewResult> continuation
)
{
return continuation(await task);
}
public static async Task ContinueWithResultAsync(this Task task, Func<Task> continuation)
public static async Task ContinueWithResult(this Task task, Func<Task> continuation)
{
await task;
await continuation();
}
public static async Task<TNewResult> ContinueWithResultAsync<TNewResult>(
public static async Task<TNewResult> ContinueWithResult<TNewResult>(
this Task task, Func<Task<TNewResult>> continuation
)
{
@ -98,12 +101,12 @@ public static class TaskExtensions
return await continuation();
}
public static async Task ContinueWithResultAsync<TResult>(this Task<TResult> task, Func<TResult, Task> continuation)
public static async Task ContinueWithResult<TResult>(this Task<TResult> task, Func<TResult, Task> continuation)
{
await continuation(await task);
}
public static async Task<TNewResult> ContinueWithResultAsync<TResult, TNewResult>(
public static async Task<TNewResult> ContinueWithResult<TResult, TNewResult>(
this Task<TResult> task, Func<TResult, Task<TNewResult>> continuation
)
{

View file

@ -286,7 +286,7 @@ public class DriveService(
.Select(p => ProcessAndStoreFileVersionAsync(p.Key, p.Value,
request.Filename))
.AwaitAllNoConcurrencyAsync()
.ContinueWithResultAsync(p => p.ToImmutableArray());
.ContinueWithResult(p => p.ToImmutableArray());
original = processed.FirstOrDefault(p => p?.format.Key == KeyEnum.Original) ??
throw new Exception("Image processing didn't result in an original version");

View file

@ -247,15 +247,15 @@ public class StorageMaintenanceService(
p.PublicAccessKey
})
.ToArrayAsync()
.ContinueWithResultAsync(res => res.SelectMany(p => new List<string?>
{
p.AccessKey,
p.ThumbnailAccessKey,
p.PublicAccessKey
})
.NotNull()
.Append(".iceshrimp-test")
.ToHashSet());
.ContinueWithResult(res => res.SelectMany(p => new List<string?>
{
p.AccessKey,
p.ThumbnailAccessKey,
p.PublicAccessKey
})
.NotNull()
.Append(".iceshrimp-test")
.ToHashSet());
logger.LogInformation("Loaded {count} files from database.", filenames.Count);
var count = 0;