Improved performance where Channel.GetUser is used
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user