diff --git a/Source/ACE.Database/SerializedShardDatabase.cs b/Source/ACE.Database/SerializedShardDatabase.cs index d8d8b006ea..01f8da80c1 100644 --- a/Source/ACE.Database/SerializedShardDatabase.cs +++ b/Source/ACE.Database/SerializedShardDatabase.cs @@ -126,11 +126,11 @@ public void SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock } - public void SaveBiotasInParallel(IEnumerable<(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock)> biotas, Action callback) + public void SaveBiotasInParallel(IEnumerable<(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock)> biotas, Action callback, bool doNotAddToCache = false) { _queue.Add(new Task(() => { - var result = BaseDatabase.SaveBiotasInParallel(biotas); + var result = BaseDatabase.SaveBiotasInParallel(biotas, doNotAddToCache); callback?.Invoke(result); })); } diff --git a/Source/ACE.Database/ShardDatabase.cs b/Source/ACE.Database/ShardDatabase.cs index e8ffbe822d..15f93ea95d 100644 --- a/Source/ACE.Database/ShardDatabase.cs +++ b/Source/ACE.Database/ShardDatabase.cs @@ -309,11 +309,11 @@ protected bool DoSaveBiota(ShardDbContext context, Biota biota) } } - public virtual bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock) + public virtual bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock, bool doNotAddToCache = false) { using (var context = new ShardDbContext()) { - var existingBiota = GetBiota(context, biota.Id); + var existingBiota = GetBiota(context, biota.Id, doNotAddToCache); rwLock.EnterReadLock(); try @@ -338,13 +338,13 @@ public virtual bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSli } } - public bool SaveBiotasInParallel(IEnumerable<(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock)> biotas) + public bool SaveBiotasInParallel(IEnumerable<(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock)> biotas, bool doNotAddToCache = false) { var result = true; Parallel.ForEach(biotas, ConfigManager.Config.Server.Threading.DatabaseParallelOptions, biota => { - if (!SaveBiota(biota.biota, biota.rwLock)) + if (!SaveBiota(biota.biota, biota.rwLock, doNotAddToCache)) result = false; }); diff --git a/Source/ACE.Database/ShardDatabaseWithCaching.cs b/Source/ACE.Database/ShardDatabaseWithCaching.cs index 20f2974a67..9c1bc0511a 100644 --- a/Source/ACE.Database/ShardDatabaseWithCaching.cs +++ b/Source/ACE.Database/ShardDatabaseWithCaching.cs @@ -134,7 +134,7 @@ public override Biota GetBiota(uint id, bool doNotAddToCache = false) return base.GetBiota(id, doNotAddToCache); } - public override bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock) + public override bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSlim rwLock, bool doNotAddToCache = false) { CacheObject cachedBiota; @@ -162,7 +162,7 @@ public override bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSl var context = new ShardDbContext(); - var existingBiota = base.GetBiota(context, biota.Id); + var existingBiota = base.GetBiota(context, biota.Id, doNotAddToCache); rwLock.EnterReadLock(); try @@ -185,7 +185,8 @@ public override bool SaveBiota(ACE.Entity.Models.Biota biota, ReaderWriterLockSl if (DoSaveBiota(context, existingBiota)) { - TryAddToCache(context, existingBiota); + if (!doNotAddToCache) + TryAddToCache(context, existingBiota); return true; } diff --git a/Source/ACE.Server/Entity/Landblock.cs b/Source/ACE.Server/Entity/Landblock.cs index fa7b917840..23e911f913 100644 --- a/Source/ACE.Server/Entity/Landblock.cs +++ b/Source/ACE.Server/Entity/Landblock.cs @@ -1173,7 +1173,7 @@ private void SaveDB() AddWorldObjectToBiotasSaveCollection(wo, biotas); } - DatabaseManager.Shard.SaveBiotasInParallel(biotas, result => { }); + DatabaseManager.Shard.SaveBiotasInParallel(biotas, null); } private void AddWorldObjectToBiotasSaveCollection(WorldObject wo, Collection<(Biota biota, ReaderWriterLockSlim rwLock)> biotas) diff --git a/Source/ACE.Server/Managers/PlayerManager.cs b/Source/ACE.Server/Managers/PlayerManager.cs index 8e84f3fcb2..f126e5c049 100644 --- a/Source/ACE.Server/Managers/PlayerManager.cs +++ b/Source/ACE.Server/Managers/PlayerManager.cs @@ -138,7 +138,7 @@ public static void SaveOfflinePlayersWithChanges() playersLock.ExitReadLock(); } - DatabaseManager.Shard.SaveBiotasInParallel(biotas, result => { }); + DatabaseManager.Shard.SaveBiotasInParallel(biotas, null, true); } diff --git a/Source/ACE.Server/WorldObjects/Player_Inventory.cs b/Source/ACE.Server/WorldObjects/Player_Inventory.cs index e337e022cc..dd9cb80070 100644 --- a/Source/ACE.Server/WorldObjects/Player_Inventory.cs +++ b/Source/ACE.Server/WorldObjects/Player_Inventory.cs @@ -189,7 +189,7 @@ private void DeepSave(WorldObject item) } } - DatabaseManager.Shard.SaveBiotasInParallel(biotas, result => { }); + DatabaseManager.Shard.SaveBiotasInParallel(biotas, null); } public enum RemoveFromInventoryAction