Skip to content
This repository was archived by the owner on Jan 25, 2025. It is now read-only.

Commit 477e636

Browse files
committed
Patch (v3.3.7)
1 parent 25d15fc commit 477e636

File tree

7 files changed

+37
-21
lines changed

7 files changed

+37
-21
lines changed

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
-- 2023.02.10 - V3.3.7
2+
3+
- refactor: Adjust MySQL connection pool sizes better
4+
- refactor: MySQL connection pool prepare to all players join at once
5+
- fix: MySQL pool size nulled on mapchange, blocking player load
6+
- fix: Block triple save on mapchange causing query timeout (RoundEnd, MapChange, Disconnect)
7+
8+
-- 2023.02.10 - V3.3.6
9+
10+
- fix: Points not changed because of misstypo
11+
112
-- 2023.02.10 - V3.3.5
213

314
- fix: Invalid player blocked from functions (problem by GetPlayers)

src/Module/Rank/RankFunctions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace K4System
66
using CounterStrikeSharp.API.Core;
77
using CounterStrikeSharp.API.Modules.Admin;
88
using CounterStrikeSharp.API.Modules.Utils;
9+
using Microsoft.Extensions.Logging;
910

1011
public partial class ModuleRank : IModuleRank
1112
{
@@ -99,7 +100,7 @@ public void ModifyPlayerPoints(CCSPlayerController player, int amount, string re
99100
if (player.IsBot || player.IsHLTV)
100101
return;
101102

102-
if (player.SteamID.ToString().Length == 17)
103+
if (player.SteamID.ToString().Length != 17)
103104
return;
104105

105106
if (!rankCache.ContainsPlayer(player))

src/Plugin/Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public override void Load(bool hotReload)
8282

8383
//** ? Initialize Database tables */
8484

85+
Database.Instance.AdjustDatabasePooling();
8586
Task.Run(CreateMultipleTablesAsync).Wait();
8687

8788
if (hotReload)
8889
{
8990
//** ? Load Player Caches */
9091

9192
LoadAllPlayersCache();
92-
AdjustDatabasePooling();
9393

9494
GameRules = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules").First().GameRules;
9595
}

src/Plugin/PluginBasics.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Plugin/PluginDatabase.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
12
using System.Data;
3+
using CounterStrikeSharp.API;
4+
using CounterStrikeSharp.API.Core;
5+
using CounterStrikeSharp.API.Modules.Memory;
26
using MySqlConnector;
37

48
namespace K4System
@@ -17,17 +21,15 @@ public void Initialize(string server, string database, string userId, string pas
1721
connectionString = BuildConnectionString(server, database, userId, password, port, sslMode, usePooling, minPoolSize, maxPoolSize);
1822
}
1923

20-
public void AdjustPoolingBasedOnPlayerCount(int playerCount)
24+
public void AdjustDatabasePooling()
2125
{
22-
if (connectionString == null) throw new InvalidOperationException("Connection string has not been initialized.");
23-
24-
uint minPoolSize = (uint)Math.Max(2, 2 + (playerCount / 10));
25-
uint maxPoolSize = (uint)Math.Max(3, 3 + (playerCount / 3));
26+
if (connectionString == null)
27+
throw new InvalidOperationException("Database has not been initialized");
2628

2729
var builder = new MySqlConnectionStringBuilder(connectionString)
2830
{
29-
MinimumPoolSize = minPoolSize,
30-
MaximumPoolSize = maxPoolSize,
31+
MinimumPoolSize = (uint)Math.Max(5, Server.MaxPlayers / 2.5),
32+
MaximumPoolSize = (uint)Math.Max(20, Server.MaxPlayers),
3133
};
3234

3335
connectionString = builder.ConnectionString;
@@ -44,8 +46,8 @@ private static string BuildConnectionString(string server, string database, stri
4446
Port = (uint)port,
4547
SslMode = Enum.Parse<MySqlSslMode>(sslMode, true),
4648
Pooling = usePooling,
47-
MinimumPoolSize = minPoolSize,
48-
MaximumPoolSize = maxPoolSize
49+
MinimumPoolSize = 10,
50+
MaximumPoolSize = 24,
4951
};
5052

5153
return builder.ConnectionString;

src/Plugin/PluginManifest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public sealed partial class Plugin : BasePlugin
1010

1111
public override string ModuleAuthor => "K4ryuu";
1212

13-
public override string ModuleVersion => "3.3.5 " +
13+
public override string ModuleVersion => "3.3.7 " +
1414
#if RELEASE
1515
"(release)";
1616
#else

src/Plugin/PluginStock.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class PlayerData
2828

2929
public sealed partial class Plugin : BasePlugin
3030
{
31-
public void AdjustDatabasePooling()
32-
{
33-
Database.Instance.AdjustPoolingBasedOnPlayerCount(Utilities.GetPlayers().Where(p => p?.IsValid == true && p.PlayerPawn?.IsValid == true && !p.IsBot && !p.IsHLTV).Count());
34-
}
35-
3631
public CommandInfo.CommandCallback CallbackAnonymizer(Action<CCSPlayerController?, CommandInfo> action)
3732
{
3833
return new CommandInfo.CommandCallback(action);

0 commit comments

Comments
 (0)