Skip to content

Commit ae7d536

Browse files
committed
alternative performance fix?
1 parent 95affe3 commit ae7d536

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Zero-K.info/Controllers/LobbyController.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public async Task<ActionResult> ChatMessages(ChatModel model)
183183
model = model ?? new ChatModel();
184184

185185
var db = new ZkDataContext();
186-
var ret = db.LobbyChatHistories.AsQueryable();
187186
bool isMuted = Punishment.GetActivePunishment(Global.AccountID, Request.UserHostAddress, 0, null, x => x.BanMute) != null;
188187
if (!string.IsNullOrEmpty(model.Channel))
189188
{
@@ -203,9 +202,10 @@ await Global.Server.GhostSay(new Say()
203202
User = Global.Account.Name,
204203
});
205204
}
206-
ret = ret
207-
.Where(x => x.Target == model.Channel && x.SayPlace == SayPlace.Channel)
208-
.OrderByDescending(x => x.LobbyChatHistoryID).Take(200);
205+
string channelName = model.Channel;
206+
model.Data = db.LobbyChatHistories
207+
.Where(x => channelName == x.Target && x.SayPlace == SayPlace.Channel)
208+
.OrderByDescending(x => x.Time);
209209
}
210210
else if (!string.IsNullOrEmpty(model.User))
211211
{
@@ -223,17 +223,18 @@ await Global.Server.GhostSay(new Say()
223223
User = Global.Account.Name,
224224
});
225225
}
226+
string otherName = model.User;
227+
string myName = Global.Account.Name;
226228
//Users can abuse rename to gain access to other users PMs, it's a feature
227-
ret = ret
228-
.Where(x => (x.User == model.User && x.Target == Global.Account.Name || x.User == Global.Account.Name && x.Target == model.User) && x.SayPlace == SayPlace.User)
229-
.OrderByDescending(x => x.LobbyChatHistoryID);
229+
model.Data = db.LobbyChatHistories
230+
.Where(x => (x.User == otherName && x.Target == myName || x.User == myName && x.Target == otherName) && x.SayPlace == SayPlace.User)
231+
.OrderByDescending(x => x.Time);
230232
}
231233
else
232234
{
233235
return PartialView("LobbyChatMessages", model);
234236
}
235237

236-
model.Data = ret;
237238
model.Message = "";
238239

239240
return PartialView("LobbyChatMessages", model);

0 commit comments

Comments
 (0)