Skip to content

Commit

Permalink
(server) Impelements export for db range command
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Apr 6, 2021
1 parent 0b31077 commit a85e31e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions hsync/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class Options : IConsoleOption
Info = "Export database bulk datas for elastic-search to json using id range", Help = "--export-for-es-range")]
public string[] ExportForESRange;

[CommandLine("--export-for-db-range", CommandType.ARGUMENTS, ArgumentsCount = 2,
Info = "Upload data to server database by user range", Help = "--export-for-db-range")]
public string[] ExportForDBRange;

/// <summary>
/// User Option
/// </summary>
Expand Down Expand Up @@ -178,6 +182,10 @@ public static void Start(string[] arguments)
{
ProcessInitServerPages(null);
}
else if (option.ExportForDBRange != null)
{
ProcessExportForDBRange(option.ExportForDBRange);
}
else if (option.ExportForES)
{
ProcessExportToES(null);
Expand Down Expand Up @@ -558,14 +566,19 @@ static void ProcessCreateDateTimeEstimator(bool low_perf)

static void ProcessInitServer(string[] args)
{
_initServerArticles();
_uploadToServerArticlesData();
}

static void ProcessInitServerPages(string[] args)
{
_initServerArticlePages();
}

static void ProcessExportForDBRange(string[] args)
{
_uploadToServerArticlesData(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]));
}

static void _initServerArticlePages()
{
var db = new SQLiteConnection("data.db");
Expand Down Expand Up @@ -611,7 +624,7 @@ static string _ggg(string nu)
return nu.Replace("\\", "\\\\").Replace("\"", "\\\"").Replace("", "\\\\").Replace("", "\\\"");
}

static void _initServerArticles()
static void _uploadToServerArticlesData(int range1 = 0, int range2 = int.MaxValue)
{
var db = new SQLiteConnection("data.db");
var count = db.ExecuteScalar<int>("SELECT COUNT(*) FROM HitomiColumnModel");
Expand All @@ -634,6 +647,10 @@ static void _initServerArticles()

Console.WriteLine($"{i}/{count}");

query = query.Where(x => range1 <= x.Id && x.Id <= range2).ToList();

if (query.Count == 0) continue;

var myCommand = conn.CreateCommand();
var transaction = conn.BeginTransaction();

Expand Down

0 comments on commit a85e31e

Please sign in to comment.