Fixed database update - general improvements
This commit is contained in:
		@@ -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){
 | 
			
		||||
 
 | 
			
		||||
@@ -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 (
 | 
			
		||||
 
 | 
			
		||||
@@ -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.");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user