9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-21 07:49:13 +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); 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 user the user to count snapshots for
* @param includePinned whether to include pinned snapshots in the search
* @return the number of snapshots this user has saved * @return the number of snapshots this user has saved
*/ */
@Blocking @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. * 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 @Override
public int getSnapshotCount(@NotNull User user, boolean includePinned) { public int getUnpinnedSnapshotCount(@NotNull User user) {
try { try {
Document filter = new Document("player_uuid", user.getUuid()); Document filter = new Document("player_uuid", user.getUuid()).append("pinned", false);
if (!includePinned) {
filter = filter.append("pinned", false);
}
return (int) mongoCollectionHelper.getCollection(userDataTable).countDocuments(filter); return (int) mongoCollectionHelper.getCollection(userDataTable).countDocuments(filter);
} catch (MongoException e) { } catch (MongoException e) {
plugin.log(Level.SEVERE, "Failed to fetch a user's current snapshot count", 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 @Override
protected void rotateSnapshots(@NotNull User user) { protected void rotateSnapshots(@NotNull User user) {
try { try {
final int unpinnedSnapshots = getSnapshotCount(user, false); final int unpinnedSnapshots = getUnpinnedSnapshotCount(user);
final int maxSnapshots = plugin.getSettings().getSynchronization().getMaxUserDataSnapshots(); final int maxSnapshots = plugin.getSettings().getSynchronization().getMaxUserDataSnapshots();
if (unpinnedSnapshots > maxSnapshots) { if (unpinnedSnapshots > maxSnapshots) {
Document filter = new Document("player_uuid", user.getUuid()).append("pinned", false); Document filter = new Document("player_uuid", user.getUuid()).append("pinned", false);

View File

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

View File

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