From 65f2c5ee705d24964db3267af91aefda4f3cba37 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 2 Mar 2021 08:48:09 +0100 Subject: [PATCH] Bit of cleaning in Scope --- src/Umbraco.Core/Scoping/Scope.cs | 48 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Core/Scoping/Scope.cs b/src/Umbraco.Core/Scoping/Scope.cs index efbfe2ded1..e79fc4ad19 100644 --- a/src/Umbraco.Core/Scoping/Scope.cs +++ b/src/Umbraco.Core/Scoping/Scope.cs @@ -40,9 +40,9 @@ namespace Umbraco.Core.Scoping public Dictionary WriteLocks; // ReadLocks and WriteLocks requested by this specific scope, required to be able to decrement - // Using HashSets works well assume that you're only gonna request a lock once pr. scope - private HashSet _readLocks; - private HashSet _writelocks; + // Using Lists just in case someone for some reason requests the same lock twice in the same scope. + private List _readLocks; + private List _writelocks; // initializes a new scope private Scope(ScopeProvider scopeProvider, @@ -70,8 +70,8 @@ namespace Umbraco.Core.Scoping ReadLocks = new Dictionary(); WriteLocks = new Dictionary(); - _readLocks = new HashSet(); - _writelocks = new HashSet(); + _readLocks = new List(); + _writelocks = new List(); #if DEBUG_SCOPES _scopeProvider.RegisterScope(this); @@ -518,14 +518,14 @@ namespace Umbraco.Core.Scoping /// Lock ID to decrement public void DecrementReadLock(int lockId) { + // If we aren't the outermost scope, pass it on to the parent. if (ParentScope != null) { ParentScope.DecrementReadLock(lockId); + return; } - else - { - ReadLocks[lockId] -= 1; - } + + ReadLocks[lockId] -= 1; } /// @@ -534,14 +534,14 @@ namespace Umbraco.Core.Scoping /// Lock ID to decrement public void DecrementWriteLock(int lockId) { + // If we aren't the outermost scope, pass it on to the parent. if (ParentScope != null) { ParentScope.DecrementWriteLock(lockId); + return; } - else - { - WriteLocks[lockId] -= 1; - } + + WriteLocks[lockId] -= 1; } /// @@ -551,15 +551,18 @@ namespace Umbraco.Core.Scoping { foreach (var id in lockIds) { - // We need to keep track of what lockIds we have requests to be able to decrement them. + // We need to keep track of what lockIds we have requested locks for to be able to decrement them. // We have to do this out of the recursion to not add the ids to all scopes. _readLocks.Add(id); } } - // Delegate acquiring the lock to the parent. ReadLockInner(lockIds); } + /// + /// Handles acquiring read locks, will delegate it to the parent if there are any. + /// + /// Array of lock object identifiers. internal void ReadLockInner(params int[] lockIds) { if (ParentScope != null) @@ -569,6 +572,7 @@ namespace Umbraco.Core.Scoping return; } + // If we are the parent, then handle the lock request. foreach (var lockId in lockIds) { // Only acquire the lock if we haven't done so yet. @@ -594,6 +598,11 @@ namespace Umbraco.Core.Scoping ReadLockInner(timeout, lockId); } + /// + /// Handles acquiring a read lock with a specified timeout, will delegate it to the parent if there are any. + /// + /// The database timeout in milliseconds. + /// The lock object identifier. internal void ReadLockInner(TimeSpan timeout, int lockId) { if (ParentScope != null) @@ -631,6 +640,10 @@ namespace Umbraco.Core.Scoping WriteLockInner(lockIds); } + /// + /// Handles acquiring write locks, will delegate it to the parent if there are any. + /// + /// Array of lock object identifiers. internal void WriteLockInner(int[] lockIds) { // If we have a parent we just delegate lock creation to parent. @@ -664,6 +677,11 @@ namespace Umbraco.Core.Scoping WriteLockInner(timeout, lockId); } + /// + /// Handles acquiring a write lock with a specified timeout, will delegate it to the parent if there are any. + /// + /// The database timeout in milliseconds. + /// The lock object identifier. internal void WriteLockInner(TimeSpan timeout, int lockId) { if (ParentScope != null)