Fixed database update - general improvements

This commit is contained in:
2024-12-22 18:47:14 +03:30
parent 3c80744b80
commit 340192d7f0
3 changed files with 11 additions and 6 deletions

View File

@@ -22,8 +22,8 @@ public class HandleDbBackup
var stream = new MemoryStream(bytes);
var postCount = await _db.CountDocumentsAsync(new BsonDocument());
var caption =
$"Backup of the database {dbname}<br>Created at {DateTime.Now:yyyy-MM-dd HH:mm:ss}<br>Current post count: {postCount}";
await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), caption, ParseMode.Html);
$"Backup of the database: {dbname}\nCreated at {DateTime.Now:yyyy-MM-dd HH:mm:ss}\nCurrent post count: {postCount}";
await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), caption);
logger?.LogInformation("Backup sent");
}
catch(Exception ex){

View File

@@ -15,9 +15,10 @@ public sealed class PostResolver
var response = await _httpClient.GetAsync(requestUrl);
// Print out ratelimit info
logger?.LogInformation("Remaining requests: " +
response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " +
response.Headers.GetValues("X-RateLimit-Reset").First());
var remainingTime = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First());
var resetTime = DateTime.Parse(response.Headers.GetValues("X-RateLimit-Reset").First());
var diff = resetTime - DateTime.UtcNow;
logger?.LogInformation($"Remaining requests: {remainingTime}, ratelimit reset in {diff.Hours} hours {diff.Minutes} minutes {diff.Seconds} seconds");
// Check if response is ok
if (

View File

@@ -48,7 +48,11 @@ public class ProcessPosts
}
// Insert post
await _db.InsertManyAsync(validPosts);
if (validPosts.Count != 0)
{
await _db.InsertManyAsync(validPosts);
}
logger?.LogInformation(
$"Proccesing done, stats: received {fetchedPosts.Count} posts, inserted and sent {newPosts} new posts.");