1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-21 15:41:19 +01:00

Fixed slow data loading error

The slowness was caused by saving to a continuous database, so a method ran multiple times
This commit is contained in:
montlikadani 2020-03-30 11:52:37 +02:00
parent 5a090c4242
commit 5177ee2213
3 changed files with 7 additions and 86 deletions

View File

@ -91,25 +91,20 @@ public class JobsPlayer {
public void addPoints(Double points) {
getPointsData().addPoints(points);
Jobs.getJobsDAO().savePoints(this);
}
public void takePoints(Double points) {
getPointsData().takePoints(points);
Jobs.getJobsDAO().savePoints(this);
}
public void setPoints(Double points) {
getPointsData().setPoints(points);
Jobs.getJobsDAO().savePoints(this);
}
public void setPoints(PlayerPoints points) {
getPointsData().setPoints(points.getCurrentPoints());
getPointsData().setTotalPoints(points.getTotalPoints());
getPointsData().setNewEntry(points.isNewEntry());
Jobs.getJobsDAO().savePoints(this);
}
public boolean havePoints(double points) {

View File

@ -1999,19 +1999,15 @@ public abstract class JobsDAO {
JobsConnection conn = getConnection();
if (conn == null)
return;
PreparedStatement prest2 = null;
try {
prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.PointsTable.getTableName() + "` WHERE `" + PointsTableFields.userid.getCollumn() + "` = ?;");
prest2.setInt(1, jPlayer.getUserId());
prest2.execute();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(prest2);
}
PreparedStatement prest = null;
try {
prest = conn.prepareStatement("DELETE FROM `" + DBTables.PointsTable.getTableName() + "` WHERE `" + PointsTableFields.userid.getCollumn() + "` = ?;");
prest.setInt(1, jPlayer.getUserId());
prest.execute();
close(prest);
prest = null;
PlayerPoints pointInfo = jPlayer.getPointsData();
prest = conn.prepareStatement("INSERT INTO `" + DBTables.PointsTable.getTableName() + "` (`" + PointsTableFields.totalpoints.getCollumn() + "`, `" + PointsTableFields.currentpoints.getCollumn()
+ "`, `" + PointsTableFields.userid.getCollumn() + "`) VALUES (?, ?, ?);");

View File

@ -1,70 +0,0 @@
/**
* Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs.dao;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;
public class JobsDrivers implements Driver {
private Driver driver;
public JobsDrivers(Driver driver) {
this.driver = driver;
}
@Override
public Connection connect(String url, Properties info) throws SQLException {
return driver.connect(url, info);
}
@Override
public boolean acceptsURL(String url) throws SQLException {
return driver.acceptsURL(url);
}
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
return driver.getPropertyInfo(url, info);
}
@Override
public int getMajorVersion() {
return driver.getMajorVersion();
}
@Override
public int getMinorVersion() {
return driver.getMinorVersion();
}
@Override
public boolean jdbcCompliant() {
return driver.jdbcCompliant();
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
return driver.getParentLogger();
}
}