From 83ec761563e7c01ae16cdbf83b42c96b8468a2f8 Mon Sep 17 00:00:00 2001 From: Mrec <66518248+RecoTG@users.noreply.github.com> Date: Sun, 17 Aug 2025 00:29:40 +0100 Subject: [PATCH] Add time index for MySQL log storage --- README.md | 7 +++++++ .../java/com/yourorg/servershop/logging/SQLLogStorage.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 7b0c3a8..b50afbc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # ShopMC MC Shop + +## Logging + +This plugin records shop transactions either to a local YAML file or to a +MySQL database. Logging and lookups run asynchronously to avoid blocking the +server thread. When using MySQL, the table is created with indexes on the +player and timestamp columns to keep queries fast. diff --git a/src/main/java/com/yourorg/servershop/logging/SQLLogStorage.java b/src/main/java/com/yourorg/servershop/logging/SQLLogStorage.java index 7d35134..43f766b 100644 --- a/src/main/java/com/yourorg/servershop/logging/SQLLogStorage.java +++ b/src/main/java/com/yourorg/servershop/logging/SQLLogStorage.java @@ -33,6 +33,8 @@ private void init() throws Exception { "amount DOUBLE NOT NULL," + "INDEX idx_player_time (player, time_ms)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); + // Ensure efficient global queries by indexing by time as well + st.executeUpdate("CREATE INDEX IF NOT EXISTS idx_time_ms ON servershop_transactions(time_ms)"); } }