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:
jjbruntonandClaude Opus 4.7 committed 2026-05-22 20:34:06 +01:00
1 parent 160172403b
commit 1b6dfd67e3
7 files changed
+407 -18

No files matched your search

+9
View File
@@ -66,6 +66,15 @@ export function runMigrations(db: Database.Database): void {
image_url TEXT
);
CREATE TABLE IF NOT EXISTS reddit_users (
t2_id TEXT PRIMARY KEY,
username TEXT NOT NULL,
mxid TEXT,
updated_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_reddit_users_username
ON reddit_users(username);
CREATE INDEX IF NOT EXISTS idx_posts_subreddit
ON processed_posts(subreddit);
CREATE INDEX IF NOT EXISTS idx_posts_processed_at