diff options
author | Jesusaves <cpntb1@ymail.com> | 2024-07-01 20:13:15 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2024-07-01 20:13:15 -0300 |
commit | 2af28bb00ed90ef9caeb6475a4297bff3e9475e9 (patch) | |
tree | 750143b985ab53ed365bb791850584b2d3a0e9ae | |
parent | 7e60db157d1f406cad108af6c096bbbc8d193f54 (diff) | |
download | serverdata-2af28bb00ed90ef9caeb6475a4297bff3e9475e9.tar.gz serverdata-2af28bb00ed90ef9caeb6475a4297bff3e9475e9.tar.bz2 serverdata-2af28bb00ed90ef9caeb6475a4297bff3e9475e9.tar.xz serverdata-2af28bb00ed90ef9caeb6475a4297bff3e9475e9.zip |
Optimization: api_sql() which is an async wrapper for SQL queries.
This should reduce freezes, specially from DelItemFromEveryPlayer.
Also fix an optimization error on picklog table cleaning.
Note that if API is disabled, it'll use query_sql normally.
-rw-r--r-- | npc/003-3/malindou.txt | 2 | ||||
-rw-r--r-- | npc/commands/kami.txt | 7 | ||||
-rw-r--r-- | npc/functions/main.txt | 14 | ||||
-rw-r--r-- | npc/functions/util.txt | 22 |
4 files changed, 33 insertions, 12 deletions
diff --git a/npc/003-3/malindou.txt b/npc/003-3/malindou.txt index 71564205a..a08b54181 100644 --- a/npc/003-3/malindou.txt +++ b/npc/003-3/malindou.txt @@ -1048,7 +1048,7 @@ OnClock0500: if (gettime(GETTIME_DAYOFMONTH) >= 7) query_sql("DELETE FROM `chatlog` WHERE `time` < '"+sqldate(-7)+"'"); // Flush picklog - if ($@HAS_API) { + if (!$@HAS_API) { query_sql("DELETE FROM `picklog` WHERE `time` < '"+sqldate(0, -1)+"'"); } else { apiasync("SQL", "DELETE FROM `picklog` WHERE `time` < '"+sqldate(0, -1)+"'"); diff --git a/npc/commands/kami.txt b/npc/commands/kami.txt index 8ac29c7f8..f32fa5e62 100644 --- a/npc/commands/kami.txt +++ b/npc/commands/kami.txt @@ -26,6 +26,13 @@ OnServMsg: } end; +OnDebug: + debugmes "Has API? %d", $@HAS_API; + debugmes "Begin, %d", gettimetick(0); + DelItemFromEveryPlayer(9999); + debugmes "Done, %d", gettimetick(0); + end; + OnBuff: .@n$=strtoupper(strcharinfo(0, "JESUSALVA", playerattached())); // Disabled command, used for debug purposes diff --git a/npc/functions/main.txt b/npc/functions/main.txt index bbb75dd40..043b92d99 100644 --- a/npc/functions/main.txt +++ b/npc/functions/main.txt @@ -457,6 +457,20 @@ function script gf_charid { return .@value$[0]; } +// api_sql( query ) +// Executes a SQL query and continue immediately without returning a value +function script api_sql { + .@sql$=getarg(0); + if (!$@HAS_API) { + query_sql(.@sql$); + } else { + apiasync("SQL", .@sql$); + apiasync("SQLRUN", ""); + } + return; +} + + // Request pincode and validate it. Use any non-4-digits code to cancel. Failure will dc you. // Returns 1 if pin check is OK. function script validatepin { diff --git a/npc/functions/util.txt b/npc/functions/util.txt index 7b833b34e..989027502 100644 --- a/npc/functions/util.txt +++ b/npc/functions/util.txt @@ -12,12 +12,12 @@ function script DelItemFromEveryPlayer { if (getarg(0, -1) < 0) return; - query_sql("DELETE FROM `inventory` WHERE `nameid`="+getarg(0)); - query_sql("DELETE FROM `cart_inventory` WHERE `nameid`="+getarg(0)); - query_sql("DELETE FROM `storage` WHERE `nameid`="+getarg(0)); - query_sql("DELETE FROM `guild_storage` WHERE `nameid`="+getarg(0)); - query_sql("DELETE FROM `rodex_items` WHERE `nameid`="+getarg(0)); - query_sql("DELETE FROM `auction` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `inventory` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `cart_inventory` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `storage` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `guild_storage` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `rodex_items` WHERE `nameid`="+getarg(0)); + api_sql("DELETE FROM `auction` WHERE `nameid`="+getarg(0)); consolewarn "Deleting item %d", getarg(0); // TODO: Delete from guild storage as well if SQL fail to? @@ -41,8 +41,8 @@ function script DelAccRegFromEveryPlayer { if (getarg(0, "error") == "error") return; - query_sql("DELETE FROM `acc_reg_num_db` WHERE `key`='"+getarg(0)+"'"); - query_sql("DELETE FROM `acc_reg_str_db` WHERE `key`='"+getarg(0)+"'"); + api_sql("DELETE FROM `acc_reg_num_db` WHERE `key`='"+getarg(0)+"'"); + api_sql("DELETE FROM `acc_reg_str_db` WHERE `key`='"+getarg(0)+"'"); if (playerattached()) detachrid(); @@ -67,8 +67,8 @@ function script DelChrRegFromEveryPlayer { if (getarg(0, "error") == "error") return; - query_sql("DELETE FROM `char_reg_num_db` WHERE `key`='"+getarg(0)+"'"); - query_sql("DELETE FROM `char_reg_str_db` WHERE `key`='"+getarg(0)+"'"); + api_sql("DELETE FROM `char_reg_num_db` WHERE `key`='"+getarg(0)+"'"); + api_sql("DELETE FROM `char_reg_str_db` WHERE `key`='"+getarg(0)+"'"); // Del variables which SQL can't reach .@org = playerattached(); @@ -93,7 +93,7 @@ function script DelQuestFromEveryPlayer { if (getarg(0, -1) < 0) return; - query_sql("DELETE FROM `quest` WHERE `quest_id`="+getarg(0)); + api_sql("DELETE FROM `quest` WHERE `quest_id`="+getarg(0)); // Del quests which SQL can't reach .@a=playerattached(); |