Implement autosave
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -73,8 +73,8 @@ public class DbHandler
|
||||
|
||||
private const string InsertIntoResume = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off;" +
|
||||
" INSERT INTO Resume (ThreadNumber, StartRange, EndRange, FirstByte, SecondByte, ThirdByte, FourthByte)" +
|
||||
" VALUES (@threadNumber, @startRange, @endRange, @firstByte, @secondByte, @thirdByte, @fourthByte);";
|
||||
" INSERT INTO Resume (ThreadNumber, StartRange, EndRange, FirstByte, SecondByte, ThirdByte, FourthByte, Paused, Completed)" +
|
||||
" VALUES (@threadNumber, @startRange, @endRange, @firstByte, @secondByte, @thirdByte, @fourthByte, @paused, @completed);";
|
||||
|
||||
private const string InsertIntoCompressedDbConnectionString = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off;" +
|
||||
@@ -86,11 +86,13 @@ public class DbHandler
|
||||
private const string ReadFilteredIdsStatement = "SELECT Id FROM Filtered WHERE Id != 0 ORDER BY Id DESC LIMIT 1;";
|
||||
private const string ReadFilteredIpStatement = "SELECT Ip1, Ip2, Ip3, Ip4 FROM Filtered WHERE Ip1 == @ip1 AND Ip2 == @ip1 AND Ip3 == @ip1 AND Ip4 == @ip1 ORDER BY Ip1 DESC LIMIT 1;";
|
||||
private const string ReadDiscardedSeqIdsStatement = "SELECT seq FROM sqlite_sequence;";
|
||||
private const string ReadAndDeleteResumeStatement = "SELECT * FROM Resume WHERE ThreadNumber == @threadNumber; DELETE FROM RESUME WHERE ThreadNumber == @threadNumber;";
|
||||
private const string ReadResumeStatement = "SELECT * FROM Resume WHERE ThreadNumber == @threadNumber;";
|
||||
private const string ReadCompressedDbRowsStatement = "SELECT Rows FROM CompressedDatabases;";
|
||||
|
||||
private const string UpdateUnfilteredStatement = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; UPDATE Unfiltered SET Filtered = 1 WHERE Id == @id;";
|
||||
|
||||
private const string UpdateResumeStatement = "UPDATE Resume SET FirstByte = @firstByte, SecondByte = @secondByte, ThirdByte = @thirdByte, FourthByte = @fourthByte, Paused = @paused, Completed = @completed WHERE ThreadNumber = @threadNumber;";
|
||||
|
||||
private const string ReIndexDatabasesStatement = "REINDEX;";
|
||||
|
||||
private const string VacuumDatabasesStatement = "VACUUM;";
|
||||
@@ -256,7 +258,7 @@ public class DbHandler
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i >= 500_000 && !_compressing)
|
||||
if (i >= 5_000_000 && !_compressing)
|
||||
{
|
||||
_compressing = true;
|
||||
|
||||
@@ -457,19 +459,31 @@ public class DbHandler
|
||||
{
|
||||
using SqliteConnection connection = new(_resumeConnectionString);
|
||||
connection.Open();
|
||||
|
||||
using SqliteCommand command = new(InsertIntoResume, connection);
|
||||
SqliteCommand command;
|
||||
|
||||
if (resumeObject.Operation == Operations.Insert)
|
||||
{
|
||||
command = new(InsertIntoResume, connection);
|
||||
command.Parameters.AddWithValue("@startRange", resumeObject.StartRange);
|
||||
command.Parameters.AddWithValue("@endRange", resumeObject.EndRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
command = new(UpdateResumeStatement, connection);
|
||||
}
|
||||
|
||||
command.Parameters.AddWithValue("@threadNumber", resumeObject.ThreadNumber);
|
||||
command.Parameters.AddWithValue("@startRange", resumeObject.StartRange);
|
||||
command.Parameters.AddWithValue("@endRange", resumeObject.EndRange);
|
||||
command.Parameters.AddWithValue("@firstByte", resumeObject.FirstByte);
|
||||
command.Parameters.AddWithValue("@secondByte", resumeObject.SecondByte);
|
||||
command.Parameters.AddWithValue("@thirdByte", resumeObject.ThirdByte);
|
||||
command.Parameters.AddWithValue("@fourthByte", resumeObject.FourthByte);
|
||||
command.Parameters.AddWithValue("@paused", resumeObject.Paused);
|
||||
command.Parameters.AddWithValue("@completed", resumeObject.Completed);
|
||||
|
||||
_ = command.ExecuteNonQuery();
|
||||
connection.Close();
|
||||
|
||||
command.Dispose();
|
||||
}
|
||||
|
||||
private void InsertCompressedDatabase(int threadNumber, long rows)
|
||||
@@ -739,7 +753,7 @@ public class DbHandler
|
||||
using SqliteConnection connection = new(_resumeConnectionString);
|
||||
connection.Open();
|
||||
|
||||
using SqliteCommand command = new(ReadAndDeleteResumeStatement, connection);
|
||||
using SqliteCommand command = new(ReadResumeStatement, connection);
|
||||
command.Parameters.AddWithValue("@threadNumber", threadNumber);
|
||||
|
||||
using SqliteDataReader reader = command.ExecuteReader();
|
||||
@@ -760,6 +774,8 @@ public class DbHandler
|
||||
resumeObject.SecondByte = reader.GetInt32(4);
|
||||
resumeObject.ThirdByte = reader.GetInt32(5);
|
||||
resumeObject.FourthByte = reader.GetInt32(6);
|
||||
resumeObject.Paused = reader.GetBoolean(7);
|
||||
resumeObject.Completed = reader.GetBoolean(8);
|
||||
}
|
||||
|
||||
return resumeObject;
|
||||
|
||||
@@ -9,4 +9,7 @@ public class ScannerResumeObject
|
||||
public int ThirdByte { get; set; }
|
||||
public int FourthByte { get; set; }
|
||||
public int ThreadNumber { get; set; }
|
||||
public Operations Operation { get; set; }
|
||||
public bool Paused { get; set; }
|
||||
public bool Completed { get; set; }
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user