test speeding up recalc queries

This commit is contained in:
rtldg 2021-10-04 14:12:47 +00:00
parent 523ce285a1
commit 4f8fd211f3

View File

@ -274,16 +274,30 @@ public void Shavit_OnDatabaseLoaded()
"CLOSE cur; " ... "CLOSE cur; " ...
"RETURN total; " ... "RETURN total; " ...
"END;;", gS_MySQLPrefix, gCV_WeightingMultiplier.FloatValue); "END;;", gS_MySQLPrefix, gCV_WeightingMultiplier.FloatValue);
if (gCV_WeightingMultiplier.FloatValue == 1.0)
{
FormatEx(sQuery, sizeof(sQuery),
"CREATE FUNCTION GetWeightedPoints(steamid INT) " ...
"RETURNS FLOAT " ...
"READS SQL DATA " ...
"BEGIN " ...
"DECLARE total FLOAT DEFAULT 0.0; " ...
"SELECT SUM(points) FROM %splayertimes WHERE auth = steamid INTO total; " ...
"RETURN total; " ...
"END;;", gS_MySQLPrefix);
}
hTrans.AddQuery(sQuery); hTrans.AddQuery(sQuery);
FormatEx(sQuery, sizeof(sQuery), FormatEx(sQuery, sizeof(sQuery),
"CREATE FUNCTION GetRecordPoints(rstyle INT, rtrack INT, rtime FLOAT, rmap VARCHAR(128), pointspertier FLOAT, stylemultiplier FLOAT, pwr FLOAT) " ... "CREATE FUNCTION GetRecordPoints(rstyle INT, rtrack INT, rtime FLOAT, rmap VARCHAR(255), pointspertier FLOAT, stylemultiplier FLOAT, pwr FLOAT, xtier INT) " ...
"RETURNS FLOAT " ... "RETURNS FLOAT " ...
"READS SQL DATA " ... "READS SQL DATA " ...
"BEGIN " ... "BEGIN " ...
"DECLARE ppoints FLOAT DEFAULT 0.0; " ... "DECLARE ppoints FLOAT DEFAULT 0.0; " ...
"DECLARE ptier INT DEFAULT 1; " ... "DECLARE ptier INT DEFAULT 1; " ...
"SELECT tier FROM %smaptiers WHERE map = rmap INTO ptier; " ... "IF rmap > '' THEN SELECT tier FROM %smaptiers WHERE map = rmap INTO ptier; ELSE SET ptier = xtier; END IF; " ...
"IF rtrack > 0 THEN SET ptier = 1; END IF; " ... "IF rtrack > 0 THEN SET ptier = 1; END IF; " ...
"SET ppoints = ((pointspertier * ptier) * 1.5) + (pwr / 15.0); " ... "SET ppoints = ((pointspertier * ptier) * 1.5) + (pwr / 15.0); " ...
"IF rtime > pwr THEN SET ppoints = ppoints * (pwr / rtime); END IF; " ... "IF rtime > pwr THEN SET ppoints = ppoints * (pwr / rtime); END IF; " ...
@ -729,7 +743,7 @@ void FormatRecalculate(bool bUseCurrentMap, int track, int style, char[] sQuery,
" WHERE style = %d %s %s%s%c %s %s"... " WHERE style = %d %s %s%s%c %s %s"...
" GROUP BY map, track, style "... " GROUP BY map, track, style "...
") as WR "... ") as WR "...
"SET PT.points = GetRecordPoints(PT.style, PT.track, PT.time, PT.map, %.1f, %.3f, WR.time) "... "SET PT.points = GetRecordPoints(PT.style, PT.track, PT.time, %s, %.1f, %.3f, WR.time, %d) "...
"WHERE PT.style = WR.style and PT.track = WR.track and PT.map = WR.map;", "WHERE PT.style = WR.style and PT.track = WR.track and PT.map = WR.map;",
gS_MySQLPrefix, gS_MySQLPrefix, style, gS_MySQLPrefix, gS_MySQLPrefix, style,
(bUseCurrentMap || track != -1) ? "AND" : "", (bUseCurrentMap || track != -1) ? "AND" : "",
@ -738,7 +752,9 @@ void FormatRecalculate(bool bUseCurrentMap, int track, int style, char[] sQuery,
(bUseCurrentMap) ? '\'' : ' ', (bUseCurrentMap) ? '\'' : ' ',
(bUseCurrentMap && track != -1) ? "AND" : "", (bUseCurrentMap && track != -1) ? "AND" : "",
sTrack, sTrack,
gCV_PointsPerTier.FloatValue, fMultiplier (bUseCurrentMap) ? "''" : "PT.map",
gCV_PointsPerTier.FloatValue, fMultiplier,
gI_Tier
); );
} }
} }