Skip to content

Commit 8173d4f

Browse files
Merge pull request #259 from rwood/adding-concurrent-propertyinfo-caching
PropertyInfo Caching on Update
2 parents 4f74f04 + be8f39f commit 8173d4f

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

QueryBuilder.Tests/QueryBuilder.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<RootNamespace>SqlKata.Tests</RootNamespace>
88
</PropertyGroup>
99
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
1011
<PackageReference Include="xunit" Version="2.3.1" />
1112
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
1213
</ItemGroup>

QueryBuilder/Query.Update.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public Query AsUpdate(IEnumerable<KeyValuePair<string, object>> values)
5555
return this;
5656
}
5757
}
58-
}
58+
}

QueryBuilder/Query.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Reflection;
@@ -312,6 +313,8 @@ public Query IncludeMany(string relationName, Query query, string foreignKey = n
312313
{
313314
return Include(relationName, query, foreignKey, localKey, isMany: true);
314315
}
316+
317+
private static readonly ConcurrentDictionary<Type, PropertyInfo[]> CacheDictionaryProperties = new ConcurrentDictionary<Type, PropertyInfo[]>();
315318

316319
/// <summary>
317320
/// Define a variable to be used within the query
@@ -355,7 +358,7 @@ public object FindVariable(string variable)
355358
private IEnumerable<KeyValuePair<string, object>> BuildKeyValuePairsFromObject(object data, bool considerKeys = false)
356359
{
357360
var dictionary = new Dictionary<string, object>();
358-
var props = data.GetType().GetRuntimeProperties();
361+
var props = CacheDictionaryProperties.GetOrAdd(data.GetType(), type => type.GetRuntimeProperties().ToArray());
359362

360363
foreach (var property in props)
361364
{

QueryBuilder/QueryBuilder.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
<Description>A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql, Oracle and Firebird</Description>
88
<Authors>Ahmad Moussawi</Authors>
99
<Copyright>Copyright (c) 2017 Ahmad Moussawi</Copyright>
10-
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
10+
<TargetFrameworks>net45;netstandard1.1</TargetFrameworks>
1111
<RootNamespace>SqlKata</RootNamespace>
1212
<AssemblyName>SqlKata</AssemblyName>
1313
</PropertyGroup>
14+
<ItemGroup>
15+
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
16+
</ItemGroup>
1417
</Project>

0 commit comments

Comments
 (0)