Store report categories with a TINYINT to save space and increase lookup performance.

This commit is contained in:
Keir 2015-10-29 23:33:23 +00:00
parent e8c01a1733
commit e266acaf44
2 changed files with 26 additions and 5 deletions

View File

@ -15,15 +15,17 @@ public enum Category
{
// descriptions borrowed from PunishPage
HACKING(Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"),
CHAT_ABUSE(Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc");
HACKING(0, Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"),
CHAT_ABUSE(1, Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc");
private int _id;
private Material _displayMaterial;
private String _title;
private List<String> _lore;
Category(Material displayMaterial, String title, String... lore)
Category(int id, Material displayMaterial, String title, String... lore)
{
this._id = id;
this._displayMaterial = displayMaterial;
this._title = title;
this._lore = new ArrayList<>();
@ -34,6 +36,11 @@ public enum Category
}
}
public int getId()
{
return _id;
}
public Material getItemMaterial()
{
return _displayMaterial;
@ -48,4 +55,17 @@ public enum Category
{
return _lore;
}
public static Category fromId(int id)
{
for (Category category : values())
{
if (category.getId() == id)
{
return category;
}
}
return null;
}
}

View File

@ -2,6 +2,7 @@ package mineplex.core.report;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnByte;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
@ -24,7 +25,7 @@ This will be used to determine if staff are handling
private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));";
private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );";
private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category VARCHAR(20), reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));";
private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category TINYINT, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));";
private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);";
private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);";
@ -57,7 +58,7 @@ This will be used to determine if staff are handling
public void logReportSending(int reportId, int reporterId, Category category, String reason)
{
executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId),
new ColumnVarChar("type", 20, category.name()), new ColumnVarChar("reason", 100, reason));
new ColumnByte("type", (byte) category.getId()), new ColumnVarChar("reason", 100, reason));
}
public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason)