mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 01:27:35 +01:00
Add a message to prevent lower performance with File
This commit is contained in:
parent
9704abc386
commit
6a0dc0300f
@ -204,6 +204,10 @@ public class AuthMe extends JavaPlugin {
|
||||
fileThread.start();
|
||||
database = fileThread;
|
||||
databaseThread = fileThread;
|
||||
final int a = database.getAccountsRegistered();
|
||||
if (a >= 1000) {
|
||||
ConsoleLogger.showError("YOUR USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
|
||||
}
|
||||
break;
|
||||
case MYSQL:
|
||||
MySQLThread sqlThread = new MySQLThread();
|
||||
@ -216,6 +220,10 @@ public class AuthMe extends JavaPlugin {
|
||||
sqliteThread.start();
|
||||
database = sqliteThread;
|
||||
databaseThread = sqliteThread;
|
||||
final int b = database.getAccountsRegistered();
|
||||
if (b >= 2000) {
|
||||
ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -213,4 +213,9 @@ public class CacheDataSource implements DataSource {
|
||||
public void purgeLogged() {
|
||||
source.purgeLogged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
return source.getAccountsRegistered();
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,6 @@ public interface DataSource {
|
||||
|
||||
void purgeLogged();
|
||||
|
||||
int getAccountsRegistered();
|
||||
|
||||
}
|
||||
|
@ -748,4 +748,31 @@ public class FlatFileThread extends Thread implements DataSource {
|
||||
public void purgeLogged() {
|
||||
PlayersLogs.getInstance().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
BufferedReader br = null;
|
||||
int result = 0;
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(source));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
result++;
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1157,4 +1157,30 @@ public class MySQLThread extends Thread implements DataSource {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
int result = 0;
|
||||
Connection con = null;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = makeSureConnectionIsReady();
|
||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||
rs = pst.executeQuery();
|
||||
if (rs != null && rs.next()) {
|
||||
result = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} catch (TimeoutException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
close(pst);
|
||||
close(con);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -597,4 +597,27 @@ public class SQLiteThread extends Thread implements DataSource {
|
||||
public void purgeLogged() {
|
||||
PlayersLogs.getInstance().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
int result = 0;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||
rs = pst.executeQuery();
|
||||
if (rs != null && rs.next()) {
|
||||
result = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} catch (TimeoutException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return result;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user