Skip to content

Commit

Permalink
[Core] More visible and easy-to-understand indexing-in and indexing-c…
Browse files Browse the repository at this point in the history
…omplete prompts (#656)

* More visible and easy-to-understand indexing-in and indexing-complete prompts

* Update LagrangeAppBuilder.cs

* Update LagrangeAppBuilder.cs
  • Loading branch information
DarkRRb authored Oct 23, 2024
1 parent 3580687 commit 946891c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Lagrange.OneBot/LagrangeAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public LagrangeAppBuilder ConfigureOneBot()
return services.GetRequiredService<ILagrangeWebServiceFactory>().Create() ?? throw new Exception("Invalid conf detected");
});

// Database
Services.AddSingleton(provider =>
{
var logger = provider.GetRequiredService<ILogger<LagrangeAppBuilder>>();
Expand All @@ -120,6 +121,9 @@ public LagrangeAppBuilder ConfigureOneBot()

string path = Configuration["ConfigPath:Database"] ?? $"lagrange-{Configuration["Account:Uin"]}.db";

bool isFirstCreate = false;
if (!File.Exists(path)) isFirstCreate = true;

var db = new LiteDatabase(path)
{
CheckpointSize = 50
Expand All @@ -135,7 +139,7 @@ public LagrangeAppBuilder ConfigureOneBot()

logger.LogWarning("In the database index");
logger.LogWarning("Depending on the size of the database will consume some time and memory");
logger.LogWarning("Please restart the program after indexing is complete");
logger.LogWarning("Not yet finished, please wait...");

hasFirstIndex = true;
break;
Expand All @@ -147,14 +151,14 @@ public LagrangeAppBuilder ConfigureOneBot()
records.EnsureIndex(BsonExpression.Create(expression));
}

if (hasFirstIndex)
// Skipping the first database creation is a restart after indexing
if (!isFirstCreate && hasFirstIndex)
{
db.Dispose(); // Ensure that the database is written correctly
logger.LogWarning("Indexing complete, please restart the program");
logger.LogInformation("Indexing Complete! Press any key to close and restart the program manually!");
Console.ReadKey(true);
Environment.Exit(0);
}

return db;
});
Services.AddSingleton<SignProvider, OneBotSigner>();
Expand Down

0 comments on commit 946891c

Please sign in to comment.