Skip to content

Commit 53ef810

Browse files
author
Jesse Nicholson
committed
Make lock mode normal, add long lock timeout, fixes
Fixes #5 Also makes locking mode normal and adds a long wait timeout for lock aquire.
1 parent 3231c06 commit 53ef810

5 files changed

Lines changed: 52 additions & 19 deletions

File tree

DistillNET/DistillNET/DistillNET/AbpFormatRuleParser.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private Filter ParseCssSelector(string rule, int selectorStartOffset, bool isExc
217217
// If it's an exception, we need to cut off three characters from the start of the CSS
218218
// selector rule because of the extra '@' character. If not an exception, we need to cut
219219
// off only the first two '##' characters.
220-
rule = rule.Substring(isException ? selectorStartOffset + 3 : selectorStartOffset + 2);//.Trim();
220+
rule = rule.Substring(isException ? selectorStartOffset + 3 : selectorStartOffset + 2);
221221

222222
return new HtmlFilter(originalRuleCopy, applicableDomains, rule, isException, categoryId);
223223
}
@@ -232,9 +232,8 @@ private Filter ParseUrlFilter(string rule, int optionsStartOffset, bool hasOptio
232232

233233
// Trim off the leading "@@" chracters if it's an exception.
234234
if(isException)
235-
{
235+
{
236236
rule = rule.Substring(2);
237-
238237
// Adjust start offset.
239238
optionsStartOffset -= 2;
240239
}
@@ -336,12 +335,12 @@ private Filter ParseUrlFilter(string rule, int optionsStartOffset, bool hasOptio
336335
var nextSpecial = rule.IndexOfAnchorEnd();
337336
if(nextSpecial != -1)
338337
{
339-
anchoredDomain = rule.Substring(0, nextSpecial);//.Trim();
340-
rule = rule.Substring(nextSpecial);//.Trim();
338+
anchoredDomain = rule.Substring(0, nextSpecial);
339+
rule = rule.Substring(nextSpecial);
341340
}
342341
else
343342
{
344-
anchoredDomain = rule;//.Trim();
343+
anchoredDomain = rule;
345344
rule = string.Empty;
346345
ruleIsGreater = false;
347346
}
@@ -373,15 +372,15 @@ private Filter ParseUrlFilter(string rule, int optionsStartOffset, bool hasOptio
373372
{
374373
case -1:
375374
{
376-
anchoredAddress = rule;//.Trim();
375+
anchoredAddress = rule;
377376
rule = string.Empty;
378377
}
379378
break;
380379

381380
default:
382381
{
383-
anchoredAddress = rule.Substring(0, nextSpecial);//.Trim();
384-
rule = rule.Substring(nextSpecial);//.Trim();
382+
anchoredAddress = rule.Substring(0, nextSpecial);
383+
rule = rule.Substring(nextSpecial);
385384
}
386385
break;
387386
}

DistillNET/DistillNET/DistillNET/Extensions/StringExtensions.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,28 @@ private static bool EqualsAt(this string str, string what, int index)
180180
return true;
181181
}
182182

183+
public static string TrimQuick(this string str)
184+
{
185+
bool trimming = true;
186+
while(trimming && str.Length > 0)
187+
{
188+
if(char.IsWhiteSpace(str[0]))
189+
{
190+
str = str.Substring(1);
191+
continue;
192+
}
193+
194+
if(char.IsWhiteSpace(str[str.Length-1]))
195+
{
196+
str = str.Substring(0, str.Length-1);
197+
continue;
198+
}
199+
200+
trimming = false;
201+
}
202+
return str;
203+
}
204+
183205
public static int LastIndexOfQuick(this string str, string what)
184206
{
185207
var whatLen = what.Length;

DistillNET/DistillNET/DistillNET/FilterDbCollection.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private async void ConfigureDatabase()
106106
cmd.CommandText = "PRAGMA journal_mode=OFF;";
107107
await cmd.ExecuteNonQueryAsync();
108108

109-
cmd.CommandText = "PRAGMA locking_mode=EXCLUSIVE;";
109+
cmd.CommandText = "PRAGMA locking_mode=NORMAL;";
110110
await cmd.ExecuteNonQueryAsync();
111111

112112
cmd.CommandText = "PRAGMA temp_store=2;";
@@ -123,6 +123,9 @@ private async void ConfigureDatabase()
123123

124124
cmd.CommandText = "PRAGMA automatic_index=FALSE;";
125125
await cmd.ExecuteNonQueryAsync();
126+
127+
cmd.CommandText = "PRAGMA busy_timeout=20000;";
128+
await cmd.ExecuteNonQueryAsync();
126129
}
127130
}
128131

@@ -197,9 +200,10 @@ public async Task<Tuple<int, int>> ParseStoreRules(string[] rawRuleStrings, shor
197200
cmd.Parameters.Add(isWhitelistParam);
198201
cmd.Parameters.Add(sourceParam);
199202

200-
var len = rawRuleStrings.Length;
203+
var len = rawRuleStrings.Length;
201204
for(int i = 0; i < len; ++i)
202205
{
206+
rawRuleStrings[i] = rawRuleStrings[i].TrimQuick();
203207
var filter = m_ruleParser.ParseAbpFormattedRule(rawRuleStrings[i], categoryId) as UrlFilter;
204208

205209
if(filter == null)
@@ -275,6 +279,7 @@ public async Task<Tuple<int, int>> ParseStoreRulesFromStream(Stream rawRulesStre
275279
using(var sw = new StreamReader(rawRulesStream))
276280
while((line = await sw.ReadLineAsync()) != null)
277281
{
282+
line = line.TrimQuick();
278283
var filter = m_ruleParser.ParseAbpFormattedRule(line, categoryId) as UrlFilter;
279284

280285
if(filter == null)
@@ -381,8 +386,8 @@ private async Task<List<UrlFilter>> GetFiltersForDomain(string domain, bool isWh
381386
break;
382387
}
383388

384-
var domainSumParam = new SQLiteParameter("$domainId", System.Data.DbType.String);
385-
cmd.Parameters.Add(domainSumParam);
389+
var domainParam = new SQLiteParameter("$domainId", System.Data.DbType.String);
390+
cmd.Parameters.Add(domainParam);
386391

387392
foreach(var sub in allPossibleVariations)
388393
{

DistillNET/DistillNET/DistillNET/UrlFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public bool IsMatch(Uri uri, NameValueCollection rawHeaders)
564564
{
565565
// Make sure that the headers match up with our options.
566566
if(this.Options != UrlFilterOptions.None)
567-
{
567+
{
568568
string headerVal = null;
569569
long xmlHttpRequestBits = ((OptionsLong & (long)UrlFilterOptions.ExceptXmlHttpRequest) | (OptionsLong & (long)UrlFilterOptions.XmlHttpRequest));
570570
if((headerVal = rawHeaders.Get("X-Requested-With")) != null)
@@ -650,10 +650,10 @@ public bool IsMatch(Uri uri, NameValueCollection rawHeaders)
650650
return false;
651651
}
652652
}
653-
653+
654654
int matchIndex = 0;
655655
foreach(var part in Parts)
656-
{
656+
{
657657
matchIndex = part.IsMatch(uri, matchIndex);
658658

659659
if(matchIndex == -1)

DistillNET/DistillNET/Properties/AssemblyInfo.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
using System.Reflection;
1+
/*
2+
* Copyright © 2017 Jesse Nicholson
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
using System.Reflection;
29
using System.Runtime.CompilerServices;
310
using System.Runtime.InteropServices;
411

@@ -32,5 +39,5 @@
3239
// You can specify all the values or you can default the Build and Revision Numbers
3340
// by using the '*' as shown below:
3441
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.4.0")]
36-
[assembly: AssemblyFileVersion("1.1.4.0")]
42+
[assembly: AssemblyVersion("1.1.5.0")]
43+
[assembly: AssemblyFileVersion("1.1.5.0")]

0 commit comments

Comments
 (0)