Rename ITransformer.CompiledExpression to Transform

This commit is contained in:
Jordan Dominion
2025-08-17 15:02:49 -04:00
parent a3e2d70f73
commit c0d94c0de3
6 changed files with 13 additions and 11 deletions
@@ -85,7 +85,7 @@ namespace Tgstation.Server.Host.Authority.Core
if (result == null)
return default;
var transformedResult = new TTransformer().CompiledExpression(result);
var transformedResult = new TTransformer().Transform(result);
return transformedResult;
}
@@ -144,7 +144,7 @@ namespace Tgstation.Server.Host.Authority.Core
if (erroredResult != null)
return erroredResult;
return CreateSuccessfulActionResult(controller, result => new TTransformer().CompiledExpression(result), authorityResponse!);
return CreateSuccessfulActionResult(controller, result => new TTransformer().Transform(result), authorityResponse!);
}
/// <inheritdoc />
@@ -611,7 +611,7 @@ namespace Tgstation.Server.Host.Authority
ValueTask SendUserUpdatedTopics(User user)
{
var transformed = new GraphQL.Transformers.UserTransformer()
.CompiledExpression(user);
.Transform(user);
return ValueTaskExtensions.WhenAll(
GraphQL.Subscriptions.UserSubscriptions.UserUpdatedTopics(
user.Require(x => x.Id))
@@ -281,7 +281,7 @@ namespace Tgstation.Server.Host.Controllers
var transformer = new TTransformer();
return PaginatedImpl(
queryGenerator,
model => transformer.CompiledExpression(model),
transformer.Transform,
null,
pageQuery,
pageSizeQuery,
@@ -23,8 +23,10 @@ namespace Tgstation.Server.Host.Models
Expression<Func<TInput, ProjectedPair<TInput, TOutput>>> ProjectedExpression { get; }
/// <summary>
/// The compiled <see cref="Expression"/>.
/// The compiled transformation <see cref="Expression"/>.
/// </summary>
Func<TInput, TOutput> CompiledExpression { get; }
/// <param name="input">The input <typeparamref name="TInput"/>.</param>
/// <returns>The transformed <typeparamref name="TOutput"/>.</returns>
TOutput Transform(TInput input);
}
}
@@ -10,7 +10,7 @@ namespace Tgstation.Server.Host.Models
abstract class TransformerBase<TInput, TOutput> : ITransformer<TInput, TOutput>
{
/// <summary>
/// <see langword="static"/> cache for <see cref="CompiledExpression"/>.
/// <see langword="static"/> cache for compiling the <see cref="Expression{TDelegate}"/> we were constructed with.
/// </summary>
static Func<TInput, TOutput>? compiledExpression; // This is safe https://stackoverflow.com/a/9647661/3976486
@@ -25,9 +25,6 @@ namespace Tgstation.Server.Host.Models
/// <inheritdoc />
public Expression<Func<TInput, ProjectedPair<TInput, TOutput>>> ProjectedExpression { get; }
/// <inheritdoc />
public Func<TInput, TOutput> CompiledExpression { get; }
/// <summary>
/// Gets the <typeparamref name="T"/> that should be used when a database projected non-null DTO value is null in the expression.
/// </summary>
@@ -188,8 +185,11 @@ namespace Tgstation.Server.Host.Models
compiledExpression ??= expression.Compile();
projectedExpression ??= expression.Projected();
Expression = expression;
CompiledExpression = compiledExpression;
ProjectedExpression = projectedExpression;
}
/// <inheritdoc />
public TOutput Transform(TInput input)
=> compiledExpression!(input);
}
}