Skip to content

Commit

Permalink
optimization: use WhereExpression with IsIn (less sql queries)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremv42 authored and NetDwarf committed Jun 3, 2021
1 parent ccda2a2 commit 6fd3097
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GameServer/managers/playermanager/FriendsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void AddPlayerFriendsListToCache(GamePlayer Player)
var offlineFriends = new FriendStatus[0];
if (friends.Any())
{
offlineFriends = Database.SelectObjects<DOLCharacters>("`Name` = @Name", friends.Select(name => new[] { new QueryParameter("@Name", name) })).SelectMany(chars => chars)
offlineFriends = Database.SelectObjects<DOLCharacters>(DB.Column("Name").IsIn(friends))
.Select(chr => new FriendStatus(chr.Name, chr.Level, chr.Class, chr.LastPlayed)).ToArray();
}

Expand Down
7 changes: 4 additions & 3 deletions GameServer/packets/Server/PacketLib1104.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ public override void SendCharacterOverview(eRealm realm)

if (charsBySlot.Any())
{
var allItems = GameServer.Database.SelectObjects<InventoryItem>("`OwnerID` = @OwnerID AND `SlotPosition` >= @MinEquipable AND `SlotPosition` <= @MaxEquipable",
charsBySlot.Select(kv => new [] { new QueryParameter("@OwnerID", kv.Value.ObjectId), new QueryParameter("@MinEquipable", (int)eInventorySlot.MinEquipable), new QueryParameter("@MaxEquipable", (int)eInventorySlot.MaxEquipable) }))
.SelectMany(objs => objs);
var ownerIdWhere = DB.Column("OwnerID").IsIn(charsBySlot.Values.Select(c => c.ObjectId));
var slotWhere = DB.Column("SlotPosition").IsGreaterOrEqualTo((int)eInventorySlot.MinEquipable)
.And(DB.Column("SlotPosition").IsLessOrEqualTo((int)eInventorySlot.MaxEquipable));
var allItems = GameServer.Database.SelectObjects<InventoryItem>(ownerIdWhere.And(slotWhere));

foreach (InventoryItem item in allItems)
{
Expand Down

0 comments on commit 6fd3097

Please sign in to comment.