Skip to content

Commit 3231c06

Browse files
author
Jesse Nicholson
committed
Get API now uses pooled connections
Use pooled connections for threaded reads from API.
1 parent 87203c9 commit 3231c06

3 files changed

Lines changed: 32 additions & 29 deletions

File tree

DistillNET/DistillNET/DistillNET.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<package >
33
<metadata>
44
<id>DistillNET</id>
5-
<version>1.0.4</version>
5+
<version>1.1.4</version>
66
<title>DistillNET</title>
77
<authors>TechnikEmpire</authors>
8-
<releaseNotes>Bug fix release resolving an issue failing to commit transactions.</releaseNotes>
8+
<releaseNotes>Modified in memory connection string, as well as filter lookup API, to enable threaded reads. Connections are now created on read (pooled) to comply with one transaction per connection.</releaseNotes>
99
<owners>TechnikEmpire</owners>
1010
<projectUrl>https://github.com/TechnikEmpire/DistillNET</projectUrl>
1111
<requireLicenseAcceptance>true</requireLicenseAcceptance>

DistillNET/DistillNET/DistillNET/FilterDbCollection.cs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ public FilterDbCollection(string dbAbsolutePath, bool overwrite = true, bool use
6666

6767
if(useMemory)
6868
{
69-
m_connection = new SQLiteConnection("Data Source=:memory:;Version=3;");
69+
m_connection = new SQLiteConnection("FullUri=file::memory:?cache=shared;Version=3;");
7070
}
7171
else
7272
{
7373
m_connection = new SQLiteConnection(string.Format("Data Source={0};Version=3;", dbAbsolutePath));
7474
}
7575

76-
m_connection.Flags = SQLiteConnectionFlags.NoConnectionPool | SQLiteConnectionFlags.NoConvertSettings | SQLiteConnectionFlags.NoVerifyTypeAffinity;
76+
m_connection.Flags = SQLiteConnectionFlags.UseConnectionPool | SQLiteConnectionFlags.NoConvertSettings | SQLiteConnectionFlags.NoVerifyTypeAffinity;
7777
m_connection.Open();
7878

7979
ConfigureDatabase();
@@ -361,41 +361,44 @@ private async Task<List<UrlFilter>> GetFiltersForDomain(string domain, bool isWh
361361

362362
var allPossibleVariations = GetAllPossibleSubdomains(domain);
363363

364-
using(var tsx = m_connection.BeginTransaction())
365-
using(var cmd = m_connection.CreateCommand())
364+
using(var myConn = new SQLiteConnection(m_connection))
366365
{
367-
switch(isWhitelist)
366+
using(var tsx = myConn.BeginTransaction())
367+
using(var cmd = myConn.CreateCommand())
368368
{
369-
case true:
369+
switch(isWhitelist)
370370
{
371-
cmd.CommandText = @"SELECT * from UrlFiltersIndex where Domains = $domainId AND IsWhitelist = 1";
372-
}
373-
break;
371+
case true:
372+
{
373+
cmd.CommandText = @"SELECT * from UrlFiltersIndex where Domains = $domainId AND IsWhitelist = 1";
374+
}
375+
break;
374376

375-
default:
376-
{
377-
cmd.CommandText = @"SELECT * from UrlFiltersIndex where Domains = $domainId AND IsWhitelist = 0";
377+
default:
378+
{
379+
cmd.CommandText = @"SELECT * from UrlFiltersIndex where Domains = $domainId AND IsWhitelist = 0";
380+
}
381+
break;
378382
}
379-
break;
380-
}
381-
382-
var domainSumParam = new SQLiteParameter("$domainId", System.Data.DbType.String);
383-
cmd.Parameters.Add(domainSumParam);
384383

385-
foreach(var sub in allPossibleVariations)
386-
{
387-
cmd.Parameters[0].Value = sub;
384+
var domainSumParam = new SQLiteParameter("$domainId", System.Data.DbType.String);
385+
cmd.Parameters.Add(domainSumParam);
388386

389-
using(var reader = await cmd.ExecuteReaderAsync())
387+
foreach(var sub in allPossibleVariations)
390388
{
391-
while(await reader.ReadAsync())
389+
cmd.Parameters[0].Value = sub;
390+
391+
using(var reader = await cmd.ExecuteReaderAsync())
392392
{
393-
short catId = reader.GetInt16(1);
394-
retVal.Add((UrlFilter)m_ruleParser.ParseAbpFormattedRule(reader.GetString(3), catId));
393+
while(await reader.ReadAsync())
394+
{
395+
short catId = reader.GetInt16(1);
396+
retVal.Add((UrlFilter)m_ruleParser.ParseAbpFormattedRule(reader.GetString(3), catId));
397+
}
395398
}
396399
}
400+
tsx.Commit();
397401
}
398-
tsx.Commit();
399402
}
400403

401404
return retVal;

DistillNET/DistillNET/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.4.0")]
36-
[assembly: AssemblyFileVersion("1.0.4.0")]
35+
[assembly: AssemblyVersion("1.1.4.0")]
36+
[assembly: AssemblyFileVersion("1.1.4.0")]

0 commit comments

Comments
 (0)