Selaa lähdekoodia

saving stats bug fix

Tigran 4 vuotta sitten
vanhempi
commit
7487196742

+ 3 - 27
MafiaTelegramBot/DataBase/Entity/StatisticsEntity.cs

@@ -14,36 +14,12 @@ namespace MafiaTelegramBot.DataBase.Entity
         public long UserId { get; set; }
         [DatabaseGenerated(DatabaseGeneratedOption.None)] [Column("role") , MaxLength(127)]
         public string Role { get; set; }
-        
-        [NotMapped]
-        private int _games = 0;
-        
+
         [Column("games") , MaxLength(127)]
-        public int Games
-        {
-            get=> _games;
-            set
-            {
-                if (_games == value) return;
-                _games = value;
-                Task.Run(async() => await StatisticsDao.Update(this));
-            }
-        }
+        public int Games { get; set; } = 0;
 
-        [NotMapped]
-        private int _wins = 0;
-        
         [Column("wins") , MaxLength(127)]
-        public int Wins
-        {
-            get=> _wins;
-            set
-            {
-                if (_wins == value) return;
-                _wins = value;
-                Task.Run(async() => await StatisticsDao.Update(this));
-            }
-        }
+        public int Wins { get; set; } = 0;
 
         public double GetWinrate()
         {

+ 1 - 6
MafiaTelegramBot/DataBase/EntityDao/StatisticsDao.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.CustomCollections;
@@ -13,14 +12,10 @@ namespace MafiaTelegramBot.DataBase.EntityDao
     {
         private static readonly MafiaDataBase DataBase = MafiaDataBase.GetInstance();
         
-        public static Task Update(StatisticsEntity statistics)
-        {
-            return Task.CompletedTask;
-        }
         public static async Task<StatisticsList> GetStatisticsListById(long userId)
         {
             var result = new StatisticsList();
-            var userStats = await UserDao.DataBase.Statistics.Where(s => s.UserId == userId).AsNoTracking().ToListAsync();
+            var userStats = await UserDao.DataBase.Statistics.Where(s => s.UserId == userId).ToListAsync();
             foreach (var role in userStats)
             {
                 result.Add(Enum.Parse<Roles>(role.Role), role);

+ 7 - 2
MafiaTelegramBot/DataBase/EntityDao/UserDao.cs

@@ -58,9 +58,10 @@ namespace MafiaTelegramBot.DataBase.EntityDao
 
         private static async Task CleanupMemory()
         {
-            await Task.Run(async () =>
+            try
             {
                 await DataBase.SaveChangesAsync();
+                Console.WriteLine($"[{DateTime.Now.ToString()}] Saving");
                 foreach (var (id, player) in ActiveUsers)
                 {
                     if (player.GetLastActivityInterval()
@@ -68,7 +69,11 @@ namespace MafiaTelegramBot.DataBase.EntityDao
                         && player.IsPlaying == false)
                         ActiveUsers.Remove(id);
                 }
-            });
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine($"[{DateTime.Now.ToString()}] {e.Message}");
+            }
         }
 
         public static async Task<long> GetIdByUsername(string messageText)

+ 2 - 2
MafiaTelegramBot/Resources/Constants.cs

@@ -6,10 +6,10 @@ namespace MafiaTelegramBot.Resources
 {
     public static class Constants
     {
-        public const bool DEBUG = true;
+        public const bool DEBUG = false;
         
         public const int PLAYER_LIMITS_MIN = DEBUG ? 1 : 6;
-        public const int MEMORY_CLEANER_INTERVAL = 60 * 60 * 1000;
+        public const int MEMORY_CLEANER_INTERVAL = DEBUG ? 20 * 1000 : 30 * 60 * 1000;
         public const int MEMORY_CLEANER_PLAYERS_COUNT = DEBUG ? 1 : 6;
         // ReSharper disable once InconsistentNaming
         public static readonly TimeSpan PLAYER_INACTIVE_INTERVAL = new(0, 40, 0);