feat(state): replace in-memory Map with SQLite-backed stateService (#59)
- Create src/services/stateService.js with get/set/delete/has API - Create migration 004_user_states.js (chat_id PK, state_data JSON, updated_at) - TTL of 24 hours — expired states auto-deleted - Cleanup job runs every hour (setInterval) - Replace src/context/userStates.js Map with async stateService proxy - Add await to all 45 userStates.get/set/delete/has calls across 13 files - Add initStates() call in index.js startup sequence - All state survives bot restarts now 18 files changed, 172 insertions, 46 deletions
This commit is contained in:
@@ -8,8 +8,11 @@ import adminHandler from './handlers/adminHandlers/adminHandler.js';
|
||||
import callbackRouter from './router/callbackRouter.js';
|
||||
import messageRouter from './router/messageRouter.js';
|
||||
|
||||
import { initStates } from './services/stateService.js';
|
||||
|
||||
await runMigrations();
|
||||
await cleanUpInvalidForeignKeys();
|
||||
await initStates();
|
||||
|
||||
const logDebug = (action, functionName) => {
|
||||
logger.debug({ action, functionName }, 'Button Press');
|
||||
|
||||
Reference in New Issue
Block a user