Removed 3 SessionsTable methods - not used:

- getPlaytime, getPlaytimeOfServer, getSessionCount
This commit is contained in:
Rsl1122 2019-02-15 09:49:37 +02:00
parent 57bc5b532e
commit f4adf4a52c
2 changed files with 10 additions and 109 deletions

View File

@ -19,19 +19,16 @@ package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.db.DBType; import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.QueryAllStatement; import com.djrapitops.plan.db.access.QueryAllStatement;
import com.djrapitops.plan.db.access.QueryStatement;
import com.djrapitops.plan.db.patches.SessionAFKTimePatch; import com.djrapitops.plan.db.patches.SessionAFKTimePatch;
import com.djrapitops.plan.db.patches.SessionsOptimizationPatch; import com.djrapitops.plan.db.patches.SessionsOptimizationPatch;
import com.djrapitops.plan.db.patches.Version10Patch; import com.djrapitops.plan.db.patches.Version10Patch;
import com.djrapitops.plan.db.sql.parsing.CreateTableParser; import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
import com.djrapitops.plan.db.sql.parsing.Sql; import com.djrapitops.plan.db.sql.parsing.Sql;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import static com.djrapitops.plan.db.sql.parsing.Sql.*; import static com.djrapitops.plan.db.sql.parsing.Sql.*;
@ -91,105 +88,6 @@ public class SessionsTable extends Table {
.toString(); .toString();
} }
/**
* Used to get Playtime after Epoch ms on a server.
*
* @param uuid UUID of the player.
* @param serverUUID UUID of the server. @see ServerTable
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if player or server not found.
*/
public long getPlaytime(UUID uuid, UUID serverUUID, long afterDate) {
String sql = SELECT +
"(SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
FROM + tableName +
WHERE + SESSION_START + ">?" +
AND + USER_UUID + "=?" +
AND + SERVER_UUID + "=?";
return query(new QueryStatement<Long>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, afterDate);
statement.setString(2, uuid.toString());
statement.setString(3, serverUUID.toString());
}
@Override
public Long processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getLong("playtime");
}
return 0L;
}
});
}
/**
* Used to get Playtime after a date of a Server.
*
* @param serverUUID UUID of the server.
* @param afterDate Epoch ms (Playtime after this date is calculated)
* @return Milliseconds played after given epoch ms on the server. 0 if server not found.
*/
public long getPlaytimeOfServer(UUID serverUUID, long afterDate) {
String sql = SELECT +
"(SUM(" + SESSION_END + ") - SUM(" + SESSION_START + ")) as playtime" +
FROM + tableName +
WHERE + SESSION_START + ">?" +
AND + SERVER_UUID + "=?";
return query(new QueryStatement<Long>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, afterDate);
statement.setString(2, serverUUID.toString());
}
@Override
public Long processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getLong("playtime");
}
return 0L;
}
});
}
/**
* Used to get total Session count of a Player on a server after a given epoch ms.
*
* @param uuid UUID of the player.
* @param serverUUID UUID of the server.
* @param afterDate Epoch ms (Session count after this date is calculated)
* @return How many sessions player has. 0 if player or server not found.
*/
public int getSessionCount(UUID uuid, UUID serverUUID, long afterDate) {
String sql = SELECT +
"COUNT(*) as login_times" +
FROM + tableName +
WHERE + SESSION_START + " >= ?" +
AND + USER_UUID + "=?" +
AND + SERVER_UUID + "=?";
return query(new QueryStatement<Integer>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setLong(1, afterDate);
statement.setString(2, uuid.toString());
statement.setString(3, serverUUID.toString());
}
@Override
public Integer processResults(ResultSet set) throws SQLException {
if (set.next()) {
return set.getInt("login_times");
}
return 0;
}
});
}
public Map<Integer, Integer> getIDServerIDRelation() { public Map<Integer, Integer> getIDServerIDRelation() {
String sql = SELECT + String sql = SELECT +
ID + ", " + ID + ", " +

View File

@ -25,6 +25,7 @@ import com.djrapitops.plan.data.store.containers.NetworkContainer;
import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.data.store.containers.ServerContainer; import com.djrapitops.plan.data.store.containers.ServerContainer;
import com.djrapitops.plan.data.store.keys.*; import com.djrapitops.plan.data.store.keys.*;
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.store.objects.DateObj;
import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.data.time.GMTimes; import com.djrapitops.plan.data.time.GMTimes;
@ -368,15 +369,17 @@ public abstract class CommonDBTest {
commitTest(); commitTest();
assertEquals(expectedLength, sessionsTable.getPlaytime(playerUUID, serverUUID, 0L)); Map<UUID, List<Session>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
assertEquals(0L, sessionsTable.getPlaytime(playerUUID, serverUUID, 30000L)); assertTrue(sessions.containsKey(serverUUID));
long playtimeOfServer = sessionsTable.getPlaytimeOfServer(serverUUID, 0L); SessionsMutator sessionsMutator = new SessionsMutator(sessions.get(serverUUID));
assertEquals(expectedLength, playtimeOfServer); SessionsMutator afterTimeSessionsMutator = sessionsMutator.filterSessionsBetween(30000, System.currentTimeMillis());
assertEquals(0L, sessionsTable.getPlaytimeOfServer(serverUUID, 30000L));
assertEquals(1, sessionsTable.getSessionCount(playerUUID, serverUUID, 0L)); assertEquals(expectedLength, sessionsMutator.toPlaytime());
assertEquals(0, sessionsTable.getSessionCount(playerUUID, serverUUID, 30000L)); assertEquals(0L, afterTimeSessionsMutator.toPlaytime());
assertEquals(1, sessionsMutator.count());
assertEquals(0, afterTimeSessionsMutator.count());
} }
@Test @Test