refactor(x-bot): x_profiles 테이블 제거, bot_x로 통합

- x_profiles 테이블 삭제 (bot_x에 프로필 정보 포함)
- saveProfile(), getProfile() 함수가 bot_x 테이블 사용하도록 수정
- Redis 캐시는 그대로 유지 (성능)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
caadiq 2026-02-08 09:42:26 +09:00
parent 5d44434e36
commit 294018c93b
3 changed files with 9 additions and 27 deletions

View file

@ -1,10 +0,0 @@
-- X 프로필 테이블
CREATE TABLE IF NOT EXISTS x_profiles (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
display_name VARCHAR(100),
avatar_url TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_username (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View file

@ -22,20 +22,16 @@ async function xBotPlugin(fastify, opts) {
}
/**
* X 프로필 저장 (DB + Redis 캐시)
* X 프로필 저장 (bot_x 테이블 + Redis 캐시)
*/
async function saveProfile(username, profile) {
if (!profile.displayName && !profile.avatarUrl) return;
// DB에 저장 (upsert)
// bot_x 테이블 업데이트
await fastify.db.query(`
INSERT INTO x_profiles (username, display_name, avatar_url)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE
display_name = VALUES(display_name),
avatar_url = VALUES(avatar_url),
updated_at = CURRENT_TIMESTAMP
`, [username, profile.displayName, profile.avatarUrl]);
UPDATE bot_x SET display_name = ?, avatar_url = ?
WHERE username = ?
`, [profile.displayName, profile.avatarUrl, username]);
// Redis 캐시에도 저장
const data = {
@ -227,7 +223,7 @@ async function xBotPlugin(fastify, opts) {
}
/**
* X 프로필 조회 (Redis 캐시 DB)
* X 프로필 조회 (Redis 캐시 bot_x 테이블)
*/
async function getProfile(username) {
// Redis 캐시 확인
@ -236,9 +232,9 @@ async function xBotPlugin(fastify, opts) {
return JSON.parse(cached);
}
// DB에서 조회
// bot_x 테이블에서 조회
const [rows] = await fastify.db.query(
'SELECT username, display_name, avatar_url, updated_at FROM x_profiles WHERE username = ?',
'SELECT username, display_name, avatar_url FROM bot_x WHERE username = ?',
[username]
);
@ -248,7 +244,6 @@ async function xBotPlugin(fastify, opts) {
username: row.username,
displayName: row.display_name,
avatarUrl: row.avatar_url,
updatedAt: row.updated_at?.toISOString(),
};
// Redis 캐시에 저장
await fastify.redis.setex(

View file

@ -316,12 +316,9 @@ fromis_9/
- `concert_setlists` - 콘서트 셋리스트
- `concert_setlist_members` - 셋리스트-멤버 연결
#### X(Twitter) 프로필
- `x_profiles` - X 프로필 캐시 (프로필 이미지, 이름 등)
#### 봇
- `bot_youtube` - YouTube 봇 설정 (채널 정보, 동기화 간격, 필터 등)
- `bot_x` - X 봇 설정 (username, 동기화 간격 등)
- `bot_x` - X 봇 설정 (username, 프로필, 동기화 간격, 필터 등)
#### 이미지
- `images` - 이미지 메타데이터 (3개 해상도 URL)