Use more specific query to get logged in players without email

- Reduces the amount of data returned from the DB and the work required to build objects
This commit is contained in:
ljacqu
2017-04-18 22:30:54 +02:00
parent 2f7ebc0ecb
commit 04ca36fe53
10 changed files with 58 additions and 76 deletions
@@ -591,18 +591,18 @@ public class SQLite implements DataSource {
}
@Override
public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<>();
String sql = "SELECT * FROM " + tableName + " WHERE " + col.IS_LOGGED + "=1;";
try (PreparedStatement pst = con.prepareStatement(sql); ResultSet rs = pst.executeQuery()) {
public List<String> getLoggedPlayersWithEmptyMail() {
List<String> players = new ArrayList<>();
String sql = "SELECT " + col.REAL_NAME + " FROM " + tableName + " WHERE " + col.IS_LOGGED + " = 1"
+ " AND (" + col.EMAIL + " = 'your@email.com' OR " + col.EMAIL + " IS NULL);";
try (Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql)) {
while (rs.next()) {
PlayerAuth auth = buildAuthFromResultSet(rs);
auths.add(auth);
players.add(rs.getString(1));
}
} catch (SQLException ex) {
logSqlException(ex);
}
return auths;
return players;
}
private PlayerAuth buildAuthFromResultSet(ResultSet row) throws SQLException {