Browse Source

Fix concurrency issue.

pull/870/head
Sebastian 4 years ago
parent
commit
373d05f740
  1. 4
      backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataObject.cs
  2. 12
      backend/src/Squidex.Infrastructure/CollectionExtensions.cs
  3. 2
      backend/src/Squidex.Infrastructure/Orleans/ActivationLimiter.cs

4
backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ContentWrapper/ContentDataObject.cs

@ -98,7 +98,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
var propertyName = property.AsString(); var propertyName = property.AsString();
fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c)).Value = value; fieldProperties.GetOrAdd(propertyName, (k, c) => new ContentDataProperty(c), this).Value = value;
return true; return true;
} }
@ -114,7 +114,7 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper
return PropertyDescriptor.Undefined; return PropertyDescriptor.Undefined;
} }
return fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c, new ContentFieldObject(c, new ContentFieldData(), false))); return fieldProperties.GetOrAdd(propertyName, (k, c) => new ContentDataProperty(c, new ContentFieldObject(c, new ContentFieldData(), false)), this);
} }
public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties() public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties()

12
backend/src/Squidex.Infrastructure/CollectionExtensions.cs

@ -331,11 +331,11 @@ namespace Squidex.Infrastructure
return dictionary.GetOrAdd(key, _ => new TValue()); return dictionary.GetOrAdd(key, _ => new TValue());
} }
public static TValue GetOrCreate<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> creator) where TKey : notnull public static TValue GetOrCreate<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory) where TKey : notnull
{ {
if (!dictionary.TryGetValue(key, out var result)) if (!dictionary.TryGetValue(key, out var result))
{ {
result = creator(key); result = valueFactory(key);
} }
return result; return result;
@ -353,11 +353,11 @@ namespace Squidex.Infrastructure
return result; return result;
} }
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> creator) where TKey : notnull public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory) where TKey : notnull
{ {
if (!dictionary.TryGetValue(key, out var result)) if (!dictionary.TryGetValue(key, out var result))
{ {
result = creator(key); result = valueFactory(key);
dictionary.Add(key, result); dictionary.Add(key, result);
} }
@ -365,11 +365,11 @@ namespace Squidex.Infrastructure
return result; return result;
} }
public static TValue GetOrAdd<TKey, TContext, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TContext context, Func<TKey, TContext, TValue> creator) where TKey : notnull public static TValue GetOrAdd<TKey, TArg, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument) where TKey : notnull
{ {
if (!dictionary.TryGetValue(key, out var result)) if (!dictionary.TryGetValue(key, out var result))
{ {
result = creator(key, context); result = valueFactory(key, factoryArgument);
dictionary.Add(key, result); dictionary.Add(key, result);
} }

2
backend/src/Squidex.Infrastructure/Orleans/ActivationLimiter.cs

@ -55,7 +55,7 @@ namespace Squidex.Infrastructure.Orleans
public void Register(Type grainType, IDeactivater deactivater, int maxActivations) public void Register(Type grainType, IDeactivater deactivater, int maxActivations)
{ {
var byType = instances.GetOrAdd(grainType, maxActivations, (t, a) => new LastUsedInstances(a)); var byType = instances.GetOrAdd(grainType, (t, a) => new LastUsedInstances(a), maxActivations);
byType.Register(deactivater); byType.Register(deactivater);
} }

Loading…
Cancel
Save