From e266acaf442357d6dbeafcb3f182cb57552260b0 Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 29 Oct 2015 23:33:23 +0000 Subject: [PATCH] Store report categories with a TINYINT to save space and increase lookup performance. --- .../src/mineplex/core/report/Category.java | 26 ++++++++++++++++--- .../core/report/ReportRepository.java | 5 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java index 1a6065bf0..734d7de81 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java @@ -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 _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; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 1f84d7c9b..9877edf58 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -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)