9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-19 14:59:21 +00:00

fix: sql syntax error with getUnpinnedSnapshotCount

This commit is contained in:
William278
2025-04-09 19:05:55 +01:00
parent 557b738511
commit cd3e4ef063
4 changed files with 12 additions and 18 deletions

View File

@@ -140,14 +140,13 @@ public abstract class Database {
public abstract List<DataSnapshot.Packed> getAllSnapshots(@NotNull User user);
/**
* Get the number of {@link DataSnapshot}s a user has
* Get the number of unpinned {@link DataSnapshot}s a user has
*
* @param user the user to count snapshots for
* @param includePinned whether to include pinned snapshots in the search
* @param user the user to count snapshots for
* @return the number of snapshots this user has saved
*/
@Blocking
public abstract int getSnapshotCount(@NotNull User user, boolean includePinned);
public abstract int getUnpinnedSnapshotCount(@NotNull User user);
/**
* Gets a specific {@link DataSnapshot} entry for a user from the database, by its UUID.

View File

@@ -235,12 +235,9 @@ public class MongoDbDatabase extends Database {
}
@Override
public int getSnapshotCount(@NotNull User user, boolean includePinned) {
public int getUnpinnedSnapshotCount(@NotNull User user) {
try {
Document filter = new Document("player_uuid", user.getUuid());
if (!includePinned) {
filter = filter.append("pinned", false);
}
Document filter = new Document("player_uuid", user.getUuid()).append("pinned", false);
return (int) mongoCollectionHelper.getCollection(userDataTable).countDocuments(filter);
} catch (MongoException e) {
plugin.log(Level.SEVERE, "Failed to fetch a user's current snapshot count", e);
@@ -273,7 +270,7 @@ public class MongoDbDatabase extends Database {
@Override
protected void rotateSnapshots(@NotNull User user) {
try {
final int unpinnedSnapshots = getSnapshotCount(user, false);
final int unpinnedSnapshots = getUnpinnedSnapshotCount(user);
final int maxSnapshots = plugin.getSettings().getSynchronization().getMaxUserDataSnapshots();
if (unpinnedSnapshots > maxSnapshots) {
Document filter = new Document("player_uuid", user.getUuid()).append("pinned", false);

View File

@@ -305,14 +305,13 @@ public class MySqlDatabase extends Database {
}
@Override
public int getSnapshotCount(@NotNull User user, boolean includePinned) {
public int getUnpinnedSnapshotCount(@NotNull User user) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
SELECT COUNT(`version_uuid`)
FROM `%user_data_table%` AND `pinned`=false OR `pinned`=?
FROM `%user_data_table%` AND `pinned`=false
WHERE `player_uuid`=?;"""))) {
statement.setString(1, user.getUuid().toString());
statement.setBoolean(2, includePinned);
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return resultSet.getInt(1);
@@ -356,7 +355,7 @@ public class MySqlDatabase extends Database {
@Blocking
@Override
protected void rotateSnapshots(@NotNull User user) {
final int unpinnedSnapshots = getSnapshotCount(user, false);
final int unpinnedSnapshots = getUnpinnedSnapshotCount(user);
final int maxSnapshots = plugin.getSettings().getSynchronization().getMaxUserDataSnapshots();
if (unpinnedSnapshots > maxSnapshots) {
try (Connection connection = getConnection()) {

View File

@@ -294,14 +294,13 @@ public class PostgresDatabase extends Database {
}
@Override
public int getSnapshotCount(@NotNull User user, boolean includePinned) {
public int getUnpinnedSnapshotCount(@NotNull User user) {
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
SELECT COUNT(`version_uuid`)
FROM `%user_data_table%` AND `pinned`=false OR `pinned`=?
FROM `%user_data_table%` AND `pinned`=false
WHERE `player_uuid`=?;"""))) {
statement.setString(1, user.getUuid().toString());
statement.setBoolean(2, includePinned);
final ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
return resultSet.getInt(1);
@@ -343,7 +342,7 @@ public class PostgresDatabase extends Database {
@Blocking
@Override
protected void rotateSnapshots(@NotNull User user) {
final int unpinnedSnapshots = getSnapshotCount(user, false);
final int unpinnedSnapshots = getUnpinnedSnapshotCount(user);
final int maxSnapshots = plugin.getSettings().getSynchronization().getMaxUserDataSnapshots();
if (unpinnedSnapshots > maxSnapshots) {
try (Connection connection = getConnection()) {