Skip to content

[Performance] Audit log store caps at 5,000 in-memory entries with no database flush #738

Description

@RUKAYAT-CODER

Overview

src/lib/audit/store.ts stores audit entries in a module-level array capped at 5,000 entries with a FIFO eviction policy. High-activity production systems exceed this cap quickly, causing old audit records to be silently lost. This is a compliance risk — audit trails must be durable for regulatory purposes.

Specifications

Features:

  • Audit entries are written to a durable database table
  • In-memory store is a short-term write buffer only

Tasks:

  • Create an audit_log database table with columns matching AuditEntry
  • Write audit entries to the database asynchronously using a queue
  • Keep a small in-memory buffer (50 entries) for recent-query performance
  • Expose a database-backed queryAuditLog() function for admin queries

Impacted Files:

  • src/lib/audit/store.ts
  • src/lib/db/ (new migration)

Acceptance Criteria

  • Audit entries are persisted to the database within 5 seconds of creation
  • Entries are not lost on server restart
  • Admin audit queries return records older than the in-memory buffer

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions