Browse Source

perf: only allocate cacheableList once

tags/2.1.0
Christopher Felegy 6 years ago
parent
commit
76f82d687b
2 changed files with 4 additions and 4 deletions
  1. +2
    -2
      src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs
  2. +2
    -2
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 2
- 2
src/Discord.Net.WebSocket/API/Gateway/MessageDeleteBulkEvent.cs View File

@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;

@@ -9,6 +9,6 @@ namespace Discord.API.Gateway
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("ids")]
public IEnumerable<ulong> Ids { get; set; }
public ulong[] Ids { get; set; }
}
}

+ 2
- 2
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1375,13 +1375,13 @@ namespace Discord.WebSocket
return;
}

var cacheableList = ImmutableArray<Cacheable<IMessage, ulong>>.Empty;
var cacheableList = new List<Cacheable<IMessage, ulong>>(data.Ids.Length);
foreach (ulong id in data.Ids)
{
var msg = SocketChannelHelper.RemoveMessage(channel, this, id);
bool isCached = msg != null;
var cacheable = new Cacheable<IMessage, ulong>(msg, id, isCached, async () => await channel.GetMessageAsync(id).ConfigureAwait(false));
cacheableList = cacheableList.Add(cacheable);
cacheableList.Add(cacheable);

if (!ExclusiveBulkDelete ?? false) // this shouldn't happen, but we'll play it safe anyways
await TimedInvokeAsync(_messageDeletedEvent, nameof(MessageDeleted), cacheable, channel).ConfigureAwait(false);


Loading…
Cancel
Save