Persist t2→username mappings in reddit_users table
Adds a durable mapping so the UI never has to show raw t2_xxx IDs or MXIDs just because the in-memory cache is cold after a restart. ChatService seeds from the table on construction and writes through every resolution path; cached chats whose username is still t2_xxx get upgraded from the DB on loadCache. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
160172403b
commit
1b6dfd67e3
7 files changed
+407
-18
No files matched your search
+6
-3
@@ -7,6 +7,7 @@ import {
|
||||
MessagesRepository,
|
||||
SuccessfulMessagesRepository,
|
||||
ActivityLogRepository,
|
||||
RedditUsersRepository,
|
||||
} from './database/repositories.js';
|
||||
import { BrowserClient } from './browser/client.js';
|
||||
import { RedditMessagePage } from './browser/message-page.js';
|
||||
@@ -79,6 +80,7 @@ export async function bootstrap(config: Config, logger: Logger): Promise<AppCont
|
||||
const messagesRepo = new MessagesRepository(db);
|
||||
const successfulMessagesRepo = new SuccessfulMessagesRepository(db);
|
||||
const activityLogRepo = new ActivityLogRepository(db);
|
||||
const redditUsersRepo = new RedditUsersRepository(db);
|
||||
logger.info('Database initialized');
|
||||
|
||||
// Browser
|
||||
@@ -208,22 +210,23 @@ export async function bootstrap(config: Config, logger: Logger): Promise<AppCont
|
||||
usernameResolver,
|
||||
undefined,
|
||||
messagesRepo,
|
||||
redditUsersRepo,
|
||||
);
|
||||
|
||||
const mediaSyncService = new MediaSyncService(chatService, logger, config.media.syncIntervalMs);
|
||||
const rateLimiter = new RateLimiter(config, logger);
|
||||
|
||||
await chatService.loadCache();
|
||||
// Lazy enrichment in the background — first sync may show t2 IDs briefly.
|
||||
chatService.enrichUsernames().catch((err) => logger.debug('enrichUsernames failed:', err));
|
||||
|
||||
// Fire-and-forget startup sync: full if we've never backfilled, delta
|
||||
// otherwise. Non-blocking so the rest of the bot can come up immediately;
|
||||
// the dashboard's sync-status banner shows progress.
|
||||
chatService
|
||||
.runStartupSync()
|
||||
.then(({ kind, chats }) => {
|
||||
.then(async ({ kind, chats }) => {
|
||||
logger.info(`[chat] startup sync (${kind}) complete: ${chats} chats`);
|
||||
// Resolve t2 IDs now that the full chat list is available.
|
||||
await chatService.enrichUsernames();
|
||||
})
|
||||
.catch((err) => logger.error('[chat] startup sync failed:', err));
|
||||
|
||||
|
||||
Reference in new issue
Block a user