mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-07 04:18:26 +02:00
Optimized playerbase total players queries
This commit is contained in:
parent
9d865ad516
commit
20e8a13ef9
@ -21,6 +21,7 @@ import com.djrapitops.plan.db.access.QueryStatement;
|
|||||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||||
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
|
||||||
|
import com.djrapitops.plan.db.sql.tables.UsersTable;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -174,7 +175,7 @@ public class PlayerCountQueries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Query<Integer> newPlayerCount(long after, long before, UUID serverUUID) {
|
public static Query<Integer> newPlayerCount(long after, long before, UUID serverUUID) {
|
||||||
String sql = SELECT + "COUNT(" + UserInfoTable.USER_UUID + ") as player_count" +
|
String sql = SELECT + "COUNT(1) as player_count" +
|
||||||
FROM + UserInfoTable.TABLE_NAME +
|
FROM + UserInfoTable.TABLE_NAME +
|
||||||
WHERE + UserInfoTable.REGISTERED + "<=?" +
|
WHERE + UserInfoTable.REGISTERED + "<=?" +
|
||||||
AND + UserInfoTable.REGISTERED + ">=?" +
|
AND + UserInfoTable.REGISTERED + ">=?" +
|
||||||
@ -183,6 +184,15 @@ public class PlayerCountQueries {
|
|||||||
return queryPlayerCount(sql, after, before, serverUUID);
|
return queryPlayerCount(sql, after, before, serverUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Query<Integer> newPlayerCount(long after, long before) {
|
||||||
|
String sql = SELECT + "COUNT(1) as player_count" +
|
||||||
|
FROM + UsersTable.TABLE_NAME +
|
||||||
|
WHERE + UsersTable.REGISTERED + "<=?" +
|
||||||
|
AND + UsersTable.REGISTERED + ">=?";
|
||||||
|
|
||||||
|
return queryPlayerCount(sql, after, before);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a EpochMs - Count map of new players on a server.
|
* Fetch a EpochMs - Count map of new players on a server.
|
||||||
*
|
*
|
||||||
|
@ -76,8 +76,8 @@ public class PlayerBaseOverviewJSONParser implements ServerTabJSONParser<Map<Str
|
|||||||
|
|
||||||
Map<String, Object> trends = new HashMap<>();
|
Map<String, Object> trends = new HashMap<>();
|
||||||
|
|
||||||
Integer playersBefore = db.query(PlayerCountQueries.uniquePlayerCount(0L, monthAgo, serverUUID));
|
Integer playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo, serverUUID));
|
||||||
Integer playersAfter = db.query(PlayerCountQueries.uniquePlayerCount(0L, now, serverUUID));
|
Integer playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now, serverUUID));
|
||||||
trends.put("total_players_then", playersBefore);
|
trends.put("total_players_then", playersBefore);
|
||||||
trends.put("total_players_now", playersAfter);
|
trends.put("total_players_now", playersAfter);
|
||||||
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
|
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
|
||||||
|
@ -76,8 +76,8 @@ public class NetworkPlayerBaseOverviewJSONParser implements NetworkTabJSONParser
|
|||||||
|
|
||||||
Map<String, Object> trends = new HashMap<>();
|
Map<String, Object> trends = new HashMap<>();
|
||||||
|
|
||||||
Integer playersBefore = db.query(PlayerCountQueries.uniquePlayerCount(0L, monthAgo));
|
Integer playersBefore = db.query(PlayerCountQueries.newPlayerCount(0L, monthAgo));
|
||||||
Integer playersAfter = db.query(PlayerCountQueries.uniquePlayerCount(0L, now));
|
Integer playersAfter = db.query(PlayerCountQueries.newPlayerCount(0L, now));
|
||||||
trends.put("total_players_then", playersBefore);
|
trends.put("total_players_then", playersBefore);
|
||||||
trends.put("total_players_now", playersAfter);
|
trends.put("total_players_now", playersAfter);
|
||||||
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
|
trends.put("total_players_trend", new Trend(playersBefore, playersAfter, false));
|
||||||
|
Loading…
Reference in New Issue
Block a user