Skip to content

Commit

Permalink
Remove quirks from main
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Nov 16, 2021
1 parent 1c2c60c commit 705a5b3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ private readonly IDictionary<Expression, Expression> _ordinalParameterBindings
private List<IncludeExpression> _pendingIncludes
= new();

private readonly bool _useOldBehavior;

private static readonly MethodInfo _toObjectMethodInfo
= typeof(CosmosProjectionBindingRemovingExpressionVisitorBase)
.GetRuntimeMethods().Single(mi => mi.Name == nameof(SafeToObject));
Expand All @@ -86,7 +84,6 @@ public CosmosProjectionBindingRemovingExpressionVisitorBase(
{
_jObjectParameter = jObjectParameter;
_trackQueryResults = trackQueryResults;
_useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26690", out var enabled) && enabled;
}

protected override Expression VisitBinary(BinaryExpression binaryExpression)
Expand All @@ -109,7 +106,7 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
storeName = projection.Alias;
}
else if (projectionExpression is UnaryExpression convertExpression
&& convertExpression.NodeType == ExpressionType.Convert)
&& convertExpression.NodeType == ExpressionType.Convert)
{
// Unwrap EntityProjectionExpression when the root entity is not projected
projectionExpression = ((UnaryExpression)convertExpression.Operand).Operand;
Expand Down Expand Up @@ -710,14 +707,10 @@ private Expression CreateGetValueExpression(
var body
= ReplacingExpressionVisitor.Replace(
converter.ConvertFromProviderExpression.Parameters.Single(),
_useOldBehavior
? Expression.Call(
jTokenParameter,
_jTokenToObjectMethodInfo.MakeGenericMethod(converter.ProviderClrType))
: Expression.Call(
jTokenParameter,
_jTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
Expression.Constant(CosmosClientWrapper.Serializer)),
Expression.Call(
jTokenParameter,
_jTokenToObjectWithSerializerMethodInfo.MakeGenericMethod(converter.ProviderClrType),
Expression.Constant(CosmosClientWrapper.Serializer)),
converter.ConvertFromProviderExpression.Body);

if (body.Type != type)
Expand Down Expand Up @@ -771,9 +764,7 @@ private Expression ConvertJTokenToType(Expression jTokenExpression, Type type)
=> type == typeof(JToken)
? jTokenExpression
: Expression.Call(
_useOldBehavior
? _toObjectMethodInfo.MakeGenericMethod(type)
: _toObjectWithSerializerMethodInfo.MakeGenericMethod(type),
_toObjectWithSerializerMethodInfo.MakeGenericMethod(type),
jTokenExpression);

private static T SafeToObject<T>(JToken token)
Expand Down
29 changes: 10 additions & 19 deletions src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2620,16 +2620,10 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
_tables.Add(subquery);
_tableReferences.Add(subqueryTableReferenceExpression);

var useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26587", out var enabled)
&& enabled;

if (!useOldBehavior)
// Remap tableReferences in inner so that all components follow referential integrity.
foreach (var tableReference in subquery._tableReferences)
{
// Remap tableReferences in inner so that all components follow referential integrity.
foreach (var tableReference in subquery._tableReferences)
{
tableReference.UpdateTableReference(this, subquery);
}
tableReference.UpdateTableReference(this, subquery);
}

var projectionMap = new Dictionary<SqlExpression, ColumnExpression>(ReferenceEqualityComparer.Instance);
Expand Down Expand Up @@ -2747,8 +2741,8 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
_orderings.Add(ordering.Update(outerColumn));
}
else if (!IsDistinct
&& GroupBy.Count == 0
|| GroupBy.Contains(orderingExpression))
&& GroupBy.Count == 0
|| GroupBy.Contains(orderingExpression))
{
_orderings.Add(
ordering.Update(
Expand All @@ -2768,13 +2762,10 @@ private SqlRemappingVisitor PushdownIntoSubqueryInternal()
subquery.ClearOrdering();
}

if (useOldBehavior)
// Remap tableReferences in inner
foreach (var tableReference in subquery._tableReferences)
{
// Remap tableReferences in inner
foreach (var tableReference in subquery._tableReferences)
{
tableReference.UpdateTableReference(this, subquery);
}
tableReference.UpdateTableReference(this, subquery);
}

var tableReferenceUpdatingExpressionVisitor = new TableReferenceUpdatingExpressionVisitor(this, subquery);
Expand Down Expand Up @@ -2819,8 +2810,8 @@ EntityProjectionExpression LiftEntityProjectionFromSubquery(EntityProjectionExpr

// Also lift nested entity projections
foreach (var navigation in entityProjection.EntityType
.GetAllBaseTypes().Concat(entityProjection.EntityType.GetDerivedTypesInclusive())
.SelectMany(t => t.GetDeclaredNavigations()))
.GetAllBaseTypes().Concat(entityProjection.EntityType.GetDerivedTypesInclusive())
.SelectMany(t => t.GetDeclaredNavigations()))
{
var boundEntityShaperExpression = entityProjection.BindNavigation(navigation);
if (boundEntityShaperExpression != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public virtual ResultSetMapping AppendBulkInsertOperation(
modificationCommands[0],
modificationCommands[0].ColumnModifications.Where(o => o.IsKey).ToList(),
modificationCommands[0].ColumnModifications.Where(o => o.IsRead).ToList(),
(!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26632", out var enabled) || !enabled)
? commandPosition
: 0);
commandPosition);
}

var readOperations = modificationCommands[0].ColumnModifications.Where(o => o.IsRead).ToList();
Expand Down
25 changes: 2 additions & 23 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,18 +826,8 @@ public virtual CoreTypeMapping? TypeMapping
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueComparer? GetValueComparer()
{
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26629", out var enabled)
&& enabled))
{
return GetValueComparer(new HashSet<IProperty>())
?? TypeMapping?.Comparer;
}

return (ValueComparer?)this[CoreAnnotationNames.ValueComparer]
?? FindFirstDifferentPrincipal()?.GetValueComparer()
=> GetValueComparer(null)
?? TypeMapping?.Comparer;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -846,18 +836,8 @@ public virtual CoreTypeMapping? TypeMapping
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueComparer? GetKeyValueComparer()
{
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26629", out var enabled)
&& enabled))
{
return GetValueComparer(new HashSet<IProperty>())
?? TypeMapping?.KeyComparer;
}

return (ValueComparer?)this[CoreAnnotationNames.ValueComparer]
?? FindFirstDifferentPrincipal()?.GetKeyValueComparer()
=> GetValueComparer(null)
?? TypeMapping?.KeyComparer;
}

private ValueComparer? GetValueComparer(HashSet<IProperty>? checkedProperties)
{
Expand Down Expand Up @@ -1041,7 +1021,6 @@ public static bool AreCompatible(IReadOnlyList<Property> properties, EntityType
property =>
property.IsShadowProperty()
|| (property.IsIndexerProperty()
&& (!AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26590", out var enabled) || !enabled)
? property.PropertyInfo == entityType.FindIndexerPropertyInfo()
: ((property.PropertyInfo != null
&& entityType.GetRuntimeProperties().ContainsKey(property.Name))
Expand Down
74 changes: 10 additions & 64 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal class SqliteConnectionFactory
{
public static readonly SqliteConnectionFactory Instance = new();

private readonly bool _newLockingBehavior;
#pragma warning disable IDE0052 // Remove unread private members
private readonly Timer _pruneTimer;
#pragma warning restore IDE0052 // Remove unread private members
Expand All @@ -23,13 +22,8 @@ internal class SqliteConnectionFactory

protected SqliteConnectionFactory()
{
_newLockingBehavior = !AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Issue26612", out var enabled) || !enabled;

if (!AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Issue26422", out enabled) || !enabled)
{
AppDomain.CurrentDomain.DomainUnload += (_, _) => ClearPools();
AppDomain.CurrentDomain.ProcessExit += (_, _) => ClearPools();
}
AppDomain.CurrentDomain.DomainUnload += (_, _) => ClearPools();
AppDomain.CurrentDomain.ProcessExit += (_, _) => ClearPools();

_pruneTimer = new Timer(PruneCallback, null, TimeSpan.FromMinutes(4), TimeSpan.FromSeconds(30));
}
Expand All @@ -56,10 +50,7 @@ public SqliteConnectionInternal GetConnection(SqliteConnection outerConnection)

public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
{
if (_newLockingBehavior)
{
_lock.EnterUpgradeableReadLock();
}
_lock.EnterUpgradeableReadLock();

try
{
Expand All @@ -69,14 +60,7 @@ public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
{
var connectionOptions = new SqliteConnectionStringBuilder(connectionString);

if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -93,25 +77,15 @@ public SqliteConnectionPoolGroup GetPoolGroup(string connectionString)
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}

return poolGroup;
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitUpgradeableReadLock();
}
_lock.ExitUpgradeableReadLock();
}
}

Expand All @@ -132,14 +106,7 @@ public void ReleasePool(SqliteConnectionPool pool, bool clearing)

public void ClearPools()
{
if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -150,14 +117,7 @@ public void ClearPools()
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}

Expand Down Expand Up @@ -188,14 +148,7 @@ private void PruneCallback(object? _)
}
}

if (_newLockingBehavior)
{
_lock.EnterWriteLock();
}
else
{
Monitor.Enter(this);
}
_lock.EnterWriteLock();

try
{
Expand All @@ -218,14 +171,7 @@ private void PruneCallback(object? _)
}
finally
{
if (_newLockingBehavior)
{
_lock.ExitWriteLock();
}
else
{
Monitor.Exit(this);
}
_lock.ExitWriteLock();
}
}
}
Expand Down

0 comments on commit 705a5b3

Please sign in to comment.