Package com.enhancedechest.log
Class ChestLogStore
java.lang.Object
com.enhancedechest.log.ChestLogStore
The chest log's own SQLite database, deliberately separate from the main chest-data database so a busy
audit log never contends with — or bloats — the store players' items live in, and so its retention can
prune freely without touching chest rows. Self-contained: it owns its connection pool and its schema,
whatever backend the main storage is configured to use.
One row per OPEN/CLOSE event. The snapshot column holds the ContainerCodec bytes of the
chest at that instant, gzip-compressed here (item NBT compresses well, ~half on typical chests) so the
on-disk cost stays modest; compression and decompression happen entirely inside this class, on the
writer thread and the async read threads, never on a tick thread.
Threading. A single physical connection (SQLite is a single-writer file; WAL keeps readers
un-blocked by the writer). All writes come from the one ChestLogService worker thread; reads
come from the shared DB executor when a GUI page is opened. The pool serialises the rare overlap,
which at log volumes is invisible.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA stored snapshot resolved back to bytes plus the chest size needed to decode it. -
Constructor Summary
ConstructorsConstructorDescriptionChestLogStore(Path dataFolder, String fileName, org.slf4j.Logger logger, Telemetry telemetry) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intcountForOwner(UUID owner, @Nullable String query) Number of log rows for an owner, for pagination.voidinit()Opens the pool and creates the schema.voidinsertBatch(List<LogWrite> batch) Inserts a batch of events in one transaction.@Nullable ChestLogStore.SnapshotBlobloadSnapshot(long id) Fetches and decompresses one event's snapshot, ornullif the row is gone (pruned).One page of an owner's log, newest first.intprune(long cutoffTs, int maxPerOwner) Applies retention: deletes events older thancutoffTs, then trims each owner to its newestmaxPerOwnerrows.
-
Constructor Details
-
ChestLogStore
-
-
Method Details
-
init
Opens the pool and creates the schema. Must be called before any read/write.- Throws:
Exception
-
insertBatch
Inserts a batch of events in one transaction. Called only from the log writer thread.- Throws:
SQLException
-
countForOwner
Number of log rows for an owner, for pagination. Whenqueryis non-null the count is limited to visits whose change list mentions it (case-insensitive substring of the diff).- Throws:
SQLException
-
page
public List<LogEntry> page(UUID owner, @Nullable @Nullable String query, int offset, int limit) throws SQLException One page of an owner's log, newest first. Deliberately omits the snapshot blob — the list only needs the headline and diff; the blob is fetched byloadSnapshot(long)on click. Whenqueryis non-null, only visits whose diff mentions it are returned.- Throws:
SQLException
-
loadSnapshot
Fetches and decompresses one event's snapshot, ornullif the row is gone (pruned).- Throws:
SQLException
-
prune
Applies retention: deletes events older thancutoffTs, then trims each owner to its newestmaxPerOwnerrows. The per-owner trim uses a window function (SQLite ≥ 3.25, well below the bundled driver's version) so it stays one statement rather than a per-owner scan.- Returns:
- total rows removed
- Throws:
SQLException
-
close
public void close()
-