Class ChestLogStore

java.lang.Object
com.enhancedechest.log.ChestLogStore

public final class ChestLogStore extends Object
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.

  • Constructor Details

    • ChestLogStore

      public ChestLogStore(Path dataFolder, String fileName, org.slf4j.Logger logger, Telemetry telemetry)
  • Method Details

    • init

      public void init() throws Exception
      Opens the pool and creates the schema. Must be called before any read/write.
      Throws:
      Exception
    • insertBatch

      public void insertBatch(List<LogWrite> batch) throws SQLException
      Inserts a batch of events in one transaction. Called only from the log writer thread.
      Throws:
      SQLException
    • countForOwner

      public int countForOwner(UUID owner, @Nullable @Nullable String query) throws SQLException
      Number of log rows for an owner, for pagination. When query is 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 by loadSnapshot(long) on click. When query is non-null, only visits whose diff mentions it are returned.
      Throws:
      SQLException
    • loadSnapshot

      @Nullable public @Nullable ChestLogStore.SnapshotBlob loadSnapshot(long id) throws SQLException
      Fetches and decompresses one event's snapshot, or null if the row is gone (pruned).
      Throws:
      SQLException
    • prune

      public int prune(long cutoffTs, int maxPerOwner) throws SQLException
      Applies retention: deletes events older than cutoffTs, then trims each owner to its newest maxPerOwner rows. 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()