Increment old stats table for ONLY pre-existing stats to solve value cap issue

This commit is contained in:
AlexTheCoder 2018-01-22 01:14:03 -05:00 committed by Alexander Meech
parent edca456e42
commit e23c3f6600
2 changed files with 30 additions and 0 deletions

View File

@ -99,11 +99,13 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>//MiniDbClientPlu
save(_statUploadQueue, map ->
{
//_repository.saveStats(map);
_repository.saveOnlyExisting(map);
_leaderboard.handleStatIncrease(map);
}, "increment");
save(_statUploadQueueOverRidable, map ->
{
//_repository.saveStats(map, true);
_repository.saveOnlyExisting(map);
_leaderboard.handleStatIncrease(map);
}, "override");
});

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Consumer;
@ -136,6 +137,33 @@ public class StatsRepository extends RepositoryBase
}
}
public void saveOnlyExisting(Map<Integer, Map<Integer, Long>> uploadQueue)
{
try (Connection c = getConnection();
PreparedStatement ps = c.prepareStatement("UPDATE accountStat SET value=value+? WHERE accountId=? AND statId=?;");
)
{
for (Entry<Integer, Map<Integer, Long>> accountEntry : uploadQueue.entrySet())
{
int accountId = accountEntry.getKey();
for (Entry<Integer, Long> statEntry : accountEntry.getValue().entrySet())
{
int statId = statEntry.getKey();
long delta = statEntry.getValue();
ps.setLong(1, delta);
ps.setInt(2, accountId);
ps.setInt(3, statId);
ps.addBatch();
}
}
ps.executeBatch();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
/**
* Saves the given stats
*