Objective
Migrate audit log creation from direct DB writes to the batched logging system.
Implementation Details
Repository Changes
- Update
AuditLogDBSource
- Add
bulk_create() method using BulkCreator
- Keep existing
create() for backward compatibility
async def bulk_create(
self,
creators: Sequence[Creator[AuditLogRow]]
) -> list[AuditLogData]:
async with self._db.begin_session() as db_sess:
result = await execute_bulk_creator(db_sess, BulkCreator(specs=[c.spec for c in creators]))
return [row.to_dataclass() for row in result.rows]
- Update
AuditLogRepository
- Route
create() calls to queue manager
- Add
flush() method for manual flush operations
Service Changes
- Update
AuditLogService
- Change
create() to enqueue instead of direct DB write
- Return immediately without waiting for DB write
Integration
- Wire LogQueueManager into AuditLogService
- Configure batch writer for audit logs
- Set Redis backup enabled for audit logs (critical)
Testing
- Test audit log enqueueing
- Test batch creation with multiple entries
- Test flush on interval and threshold
- Integration tests with real DB
Migration Strategy
- Feature flag for gradual rollout
- Monitor queue depth and flush latency
- Rollback plan if issues detected
Acceptance Criteria
- Audit logs written in batches
- No functional regression
- Reduced DB transaction count (target: 90%)
- All tests passing
JIRA Issue: BA-4234
Objective
Migrate audit log creation from direct DB writes to the batched logging system.
Implementation Details
Repository Changes
AuditLogDBSourcebulk_create()method usingBulkCreatorcreate()for backward compatibilityAuditLogRepositorycreate()calls to queue managerflush()method for manual flush operationsService Changes
AuditLogServicecreate()to enqueue instead of direct DB writeIntegration
Testing
Migration Strategy
Acceptance Criteria
JIRA Issue: BA-4234