Only create transaction when we use it

This commit is contained in:
Jackzie 2023-07-20 12:23:33 -05:00 committed by GitHub
parent d397b1e10d
commit 1148a2b689
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,8 +158,9 @@ public Action Timer_PushLogs(Handle h) {
static char query[1024]; static char query[1024];
static Log log; static Log log;
int length = logs.Length; int length = logs.Length;
Transaction transaction = new Transaction();
if(length > 0) { if(length > 0) {
Transaction transaction = new Transaction();
for(int i = 0; i < length; i++) { for(int i = 0; i < length; i++) {
logs.GetArray(i, log, sizeof(log)); logs.GetArray(i, log, sizeof(log));
g_db.Format(query, sizeof(query), "INSERT INTO `activity_log` (`timestamp`, `server`, `type`, `client`, `target`, `message`) VALUES (%d, NULLIF('%s', ''), '%s', NULLIF('%s', ''), NULLIF('%s', ''), NULLIF('%s', ''))", g_db.Format(query, sizeof(query), "INSERT INTO `activity_log` (`timestamp`, `server`, `type`, `client`, `target`, `message`) VALUES (%d, NULLIF('%s', ''), '%s', NULLIF('%s', ''), NULLIF('%s', ''), NULLIF('%s', ''))",
@ -173,11 +174,11 @@ public Action Timer_PushLogs(Handle h) {
transaction.AddQuery(query); transaction.AddQuery(query);
} }
logs.Resize(logs.Length - length); logs.Resize(logs.Length - length);
g_db.Execute(transaction, _, SQL_TransactionFailed, length, DBPrio_Low);
} }
g_db.Execute(transaction, _, SQL_TransactionFailed, length, DBPrio_Low);
return Plugin_Continue; return Plugin_Continue;
} }
public void SQL_TransactionFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) { void SQL_TransactionFailed(Database db, any data, int numQueries, const char[] error, int failIndex, any[] queryData) {
LogError("Push transaction failed: %s at query %d/%d", error, failIndex, numQueries); LogError("Push transaction failed: %s at query %d/%d", error, failIndex, numQueries);
} }