Browse Source

Improved performance where Channel.GetUser is used

tags/docs-0.9
RogueException 9 years ago
parent
commit
d7ecefb5cb
3 changed files with 21 additions and 6 deletions
  1. +2
    -1
      src/Discord.Net/DiscordClient.cs
  2. +17
    -3
      src/Discord.Net/Models/Channel.cs
  3. +2
    -2
      src/Discord.Net/Models/Message.cs

+ 2
- 1
src/Discord.Net/DiscordClient.cs View File

@@ -807,7 +807,8 @@ namespace Discord
Channel channel = GetChannel(data.ChannelId);
if (channel != null)
{
var user = channel.GetUser(data.Author.Id);
var user = channel.GetUserFast(data.Author.Id);

if (user != null)
{
Message msg = null;


+ 17
- 3
src/Discord.Net/Models/Channel.cs View File

@@ -275,7 +275,7 @@ namespace Discord
if (_messages.TryGetValue(id, out result))
return result;
}
return new Message(id, this, userId != null ? GetUser(userId.Value) : null);
return new Message(id, this, userId != null ? GetUserFast(userId.Value) : null);
}

public async Task<Message[]> DownloadMessages(int limit = 100, ulong? relativeMessageId = null,
@@ -298,13 +298,13 @@ namespace Discord
Message msg = null;
if (useCache)
{
msg = AddMessage(x.Id, GetUser(x.Author.Id), x.Timestamp.Value);
msg = AddMessage(x.Id, GetUserFast(x.Author.Id), x.Timestamp.Value);
var user = msg.User;
if (user != null)
user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
}
else
msg = new Message(x.Id, this, GetUser(x.Author.Id));
msg = new Message(x.Id, this, GetUserFast(x.Author.Id));
msg.Update(x);
return msg;
})
@@ -573,6 +573,20 @@ namespace Discord
}
return null;
}
internal User GetUserFast(ulong id)
{
//Can return users not in this channel, but that's usually okay
if (IsPrivate)
{
if (id == Recipient.Id)
return Recipient;
else if (id == Client.PrivateUser.Id)
return Client.PrivateUser;
}
else
return Server.GetUser(id);
return null;
}
#endregion

internal Channel Clone()


+ 2
- 2
src/Discord.Net/Models/Message.cs View File

@@ -36,7 +36,7 @@ namespace Discord
ulong id;
if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id))
{
var user = channel.GetUser(id);
var user = channel.GetUserFast(id);
if (user != null)
{
if (users != null)
@@ -276,7 +276,7 @@ namespace Discord
if (model.Mentions != null)
{
MentionedUsers = model.Mentions
.Select(x => Channel.GetUser(x.Id))
.Select(x => Channel.GetUserFast(x.Id))
.Where(x => x != null)
.ToArray();
}


Loading…
Cancel
Save