Speed up /v1/network/servers by 66%

Benchmark: endpoint (fetchPeakPlayerCount is the highest contributor)
- Before: 10 seconds (1s * server count)
- Before: 3 seconds (332ms * server count)
This commit is contained in:
Aurora Lahtela 2023-02-12 10:37:52 +02:00
parent 55d2366d4b
commit 226bc20e3f
1 changed files with 6 additions and 6 deletions

View File

@ -216,14 +216,15 @@ public class TPSQueries {
}
public static Query<Optional<DateObj<Integer>>> fetchPeakPlayerCount(ServerUUID serverUUID, long afterDate) {
String subQuery = '(' + SELECT + "MAX(" + PLAYERS_ONLINE + ')' + FROM + TABLE_NAME + WHERE + SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID +
String subQuery = '(' + SELECT + DATE + ",MAX(" + PLAYERS_ONLINE + ") as " + PLAYERS_ONLINE + FROM + TABLE_NAME +
WHERE + SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID +
AND + DATE + ">= ?)";
String sql = SELECT +
DATE + ',' + PLAYERS_ONLINE +
FROM + TABLE_NAME +
"t." + DATE + ',' + "t." + PLAYERS_ONLINE +
FROM + TABLE_NAME + " t" +
INNER_JOIN + subQuery + " max on t." + DATE + "=max." + DATE + AND + "t." + PLAYERS_ONLINE + "=max." + PLAYERS_ONLINE +
WHERE + SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID +
AND + DATE + ">= ?" +
AND + PLAYERS_ONLINE + "=" + subQuery +
AND + "t." + DATE + ">= ?" +
ORDER_BY + DATE + " DESC LIMIT 1";
return new QueryStatement<>(sql) {
@ -248,7 +249,6 @@ public class TPSQueries {
};
}
@Benchmark.Slow("1s")
public static Query<Optional<DateObj<Integer>>> fetchAllTimePeakPlayerCount(ServerUUID serverUUID) {
return fetchPeakPlayerCount(serverUUID, 0);
}