From: Pieter-Jan Briers Date: Tue, 20 Aug 2024 21:32:11 +0000 (+0200) Subject: Don't create new JsonSerializerOptions for every discord webhook (#31240) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=d63115d1f76ecbee0618b93a196ff57f49be816f;p=space-station-14.git Don't create new JsonSerializerOptions for every discord webhook (#31240) *sigh* --- diff --git a/Content.Server/Discord/DiscordWebhook.cs b/Content.Server/Discord/DiscordWebhook.cs index 878cd5975a..3881f5ef4b 100644 --- a/Content.Server/Discord/DiscordWebhook.cs +++ b/Content.Server/Discord/DiscordWebhook.cs @@ -8,6 +8,9 @@ namespace Content.Server.Discord; public sealed class DiscordWebhook : IPostInjectInit { + private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions + { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; + [Dependency] private readonly ILogManager _log = default!; private const string BaseUrl = "https://discord.com/api/v10/webhooks"; @@ -68,7 +71,7 @@ public sealed class DiscordWebhook : IPostInjectInit public async Task CreateMessage(WebhookIdentifier identifier, WebhookPayload payload) { var url = $"{GetUrl(identifier)}?wait=true"; - var response = await _http.PostAsJsonAsync(url, payload, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }); + var response = await _http.PostAsJsonAsync(url, payload, JsonOptions); LogResponse(response, "Create"); @@ -101,7 +104,7 @@ public sealed class DiscordWebhook : IPostInjectInit public async Task EditMessage(WebhookIdentifier identifier, ulong messageId, WebhookPayload payload) { var url = $"{GetUrl(identifier)}/messages/{messageId}"; - var response = await _http.PatchAsJsonAsync(url, payload, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }); + var response = await _http.PatchAsJsonAsync(url, payload, JsonOptions); LogResponse(response, "Edit");