diff --git a/backend/src/services/x/index.js b/backend/src/services/x/index.js index 2c2d254..43d1f0f 100644 --- a/backend/src/services/x/index.js +++ b/backend/src/services/x/index.js @@ -61,6 +61,20 @@ async function xBotPlugin(fastify, opts) { return null; } + // 리트윗 이중 저장 방지: 같은 리트윗이 타임라인에서 래퍼 id / 원본 id 두 형태로 + // 번갈아 나타나 post_id가 달라도 같은 트윗인 경우가 있음. + // hydration으로 양쪽 모두 전체 내용을 갖추므로 동일 내용이면 중복 처리. + // username은 형태에 따라 원작자/봇계정으로 불일치할 수 있어 둘 다 매칭. + if (tweet.isRetweet && tweet.text) { + const [dup] = await fastify.db.query( + 'SELECT id FROM schedule_x WHERE content = ? AND username IN (?, ?) LIMIT 1', + [tweet.text, tweet.originalUsername || username, username] + ); + if (dup.length > 0) { + return null; + } + } + const date = formatDate(tweet.time); const time = formatTime(tweet.time); const title = extractTitle(tweet.text);