@@ -6,9 +6,12 @@ namespace K4System
66 using CounterStrikeSharp . API . Core ;
77 using CounterStrikeSharp . API . Modules . Commands ;
88 using CounterStrikeSharp . API . Modules . Utils ;
9+ using Microsoft . Extensions . Logging ;
910
1011 public sealed partial class Plugin : BasePlugin
1112 {
13+ public Timer ? databasePoolingTimer ;
14+
1215 public void Initialize_Commands ( )
1316 {
1417 AddCommand ( "css_k4" , "More informations about K4-System" ,
@@ -83,7 +86,6 @@ public void Initialize_Events()
8386 return HookResult . Continue ;
8487
8588 LoadPlayerCache ( player ) ;
86- AdjustDatabasePooling ( ) ;
8789
8890 return HookResult . Continue ;
8991 } ) ;
@@ -101,8 +103,12 @@ public void Initialize_Events()
101103 if ( Config . GeneralSettings . ModuleTimes )
102104 ModuleTime . BeforeDisconnect ( player ) ;
103105
104- SavePlayerCache ( player ) ;
105- AdjustDatabasePooling ( ) ;
106+ // Block save if the disconenct reason is mapchange, because we handle it on RoundEnd for everyone, which called on MapChange
107+ // This reduce the load, because we use transactions and we don't open connection for each player
108+ if ( @event . Reason == 1 )
109+ {
110+ SavePlayerCache ( player ) ;
111+ }
106112
107113 return HookResult . Continue ;
108114 } ) ;
@@ -123,7 +129,7 @@ public void Initialize_Events()
123129 if ( player . IsBot || player . IsHLTV )
124130 continue ;
125131
126- if ( player . SteamID . ToString ( ) . Length = = 17 )
132+ if ( player . SteamID . ToString ( ) . Length ! = 17 )
127133 continue ;
128134
129135 player . PrintToChat ( $ " { Localizer [ "k4.general.prefix" ] } { ChatColors . Lime } { Localizer [ "k4.general.spawnmessage" ] } ") ;
@@ -141,6 +147,7 @@ public void Initialize_Events()
141147 ModuleRank . BeforeRoundEnd ( @event . Winner ) ;
142148
143149 SaveAllPlayersCache ( ) ;
150+
144151 return HookResult . Continue ;
145152 } ) ;
146153
0 commit comments