Skip to content

Commit

Permalink
alternative performance fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
DeinFreund committed May 17, 2020
1 parent 95affe3 commit ae7d536
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Zero-K.info/Controllers/LobbyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public async Task<ActionResult> ChatMessages(ChatModel model)
model = model ?? new ChatModel();

var db = new ZkDataContext();
var ret = db.LobbyChatHistories.AsQueryable();
bool isMuted = Punishment.GetActivePunishment(Global.AccountID, Request.UserHostAddress, 0, null, x => x.BanMute) != null;
if (!string.IsNullOrEmpty(model.Channel))
{
Expand All @@ -203,9 +202,10 @@ await Global.Server.GhostSay(new Say()
User = Global.Account.Name,
});
}
ret = ret
.Where(x => x.Target == model.Channel && x.SayPlace == SayPlace.Channel)
.OrderByDescending(x => x.LobbyChatHistoryID).Take(200);
string channelName = model.Channel;
model.Data = db.LobbyChatHistories
.Where(x => channelName == x.Target && x.SayPlace == SayPlace.Channel)
.OrderByDescending(x => x.Time);
}
else if (!string.IsNullOrEmpty(model.User))
{
Expand All @@ -223,17 +223,18 @@ await Global.Server.GhostSay(new Say()
User = Global.Account.Name,
});
}
string otherName = model.User;
string myName = Global.Account.Name;
//Users can abuse rename to gain access to other users PMs, it's a feature
ret = ret
.Where(x => (x.User == model.User && x.Target == Global.Account.Name || x.User == Global.Account.Name && x.Target == model.User) && x.SayPlace == SayPlace.User)
.OrderByDescending(x => x.LobbyChatHistoryID);
model.Data = db.LobbyChatHistories
.Where(x => (x.User == otherName && x.Target == myName || x.User == myName && x.Target == otherName) && x.SayPlace == SayPlace.User)
.OrderByDescending(x => x.Time);
}
else
{
return PartialView("LobbyChatMessages", model);
}

model.Data = ret;
model.Message = "";

return PartialView("LobbyChatMessages", model);
Expand Down

0 comments on commit ae7d536

Please sign in to comment.