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:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user