Improved performance where Channel.GetUser is used
This commit is contained in:
@@ -807,7 +807,8 @@ namespace Discord
|
|||||||
Channel channel = GetChannel(data.ChannelId);
|
Channel channel = GetChannel(data.ChannelId);
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
{
|
{
|
||||||
var user = channel.GetUser(data.Author.Id);
|
var user = channel.GetUserFast(data.Author.Id);
|
||||||
|
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
Message msg = null;
|
Message msg = null;
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ namespace Discord
|
|||||||
if (_messages.TryGetValue(id, out result))
|
if (_messages.TryGetValue(id, out result))
|
||||||
return 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,
|
public async Task<Message[]> DownloadMessages(int limit = 100, ulong? relativeMessageId = null,
|
||||||
@@ -298,13 +298,13 @@ namespace Discord
|
|||||||
Message msg = null;
|
Message msg = null;
|
||||||
if (useCache)
|
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;
|
var user = msg.User;
|
||||||
if (user != null)
|
if (user != null)
|
||||||
user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
|
user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
msg = new Message(x.Id, this, GetUser(x.Author.Id));
|
msg = new Message(x.Id, this, GetUserFast(x.Author.Id));
|
||||||
msg.Update(x);
|
msg.Update(x);
|
||||||
return msg;
|
return msg;
|
||||||
})
|
})
|
||||||
@@ -573,6 +573,20 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
return null;
|
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
|
#endregion
|
||||||
|
|
||||||
internal Channel Clone()
|
internal Channel Clone()
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace Discord
|
|||||||
ulong id;
|
ulong id;
|
||||||
if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out 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 (user != null)
|
||||||
{
|
{
|
||||||
if (users != null)
|
if (users != null)
|
||||||
@@ -276,7 +276,7 @@ namespace Discord
|
|||||||
if (model.Mentions != null)
|
if (model.Mentions != null)
|
||||||
{
|
{
|
||||||
MentionedUsers = model.Mentions
|
MentionedUsers = model.Mentions
|
||||||
.Select(x => Channel.GetUser(x.Id))
|
.Select(x => Channel.GetUserFast(x.Id))
|
||||||
.Where(x => x != null)
|
.Where(x => x != null)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user