]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Don't create new JsonSerializerOptions for every discord webhook (#31240)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Tue, 20 Aug 2024 21:32:11 +0000 (23:32 +0200)
committerGitHub <noreply@github.com>
Tue, 20 Aug 2024 21:32:11 +0000 (23:32 +0200)
*sigh*

Content.Server/Discord/DiscordWebhook.cs

index 878cd5975ae89ec23feeeefcbe9534e659548b74..3881f5ef4bfb81b6a400d1996d0713733f82d59f 100644 (file)
@@ -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<HttpResponseMessage> 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<HttpResponseMessage> 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");