feat: 完善 signals 热度筛选与展示交互

This commit is contained in:
2026-02-24 17:31:43 +08:00
parent f157174341
commit ff6f12be21
12 changed files with 541 additions and 134 deletions
+76
View File
@@ -0,0 +1,76 @@
import { PrismaClient } from '@prisma/client'
import { computeSignalHotness } from '../src/lib/signal-hotness'
import type { SignalSource } from '../src/lib/validations'
const prisma = new PrismaClient()
function isSignalSource(value: string): value is SignalSource {
return (
value === 'hacker_news' ||
value === 'github' ||
value === 'arxiv' ||
value === 'hugging_face' ||
value === 'reddit' ||
value === 'product_hunt'
)
}
async function main() {
console.log('[signals-hot] start backfill')
const rows = await prisma.signal.findMany({
select: {
id: true,
source: true,
engagement: true,
publishedAt: true,
hotScore: true,
isHot: true,
},
})
let updated = 0
let skipped = 0
for (const row of rows) {
if (!isSignalSource(row.source)) {
skipped += 1
continue
}
const next = computeSignalHotness({
source: row.source,
engagement: row.engagement,
publishedAt: row.publishedAt,
})
if (row.hotScore === next.hotScore && row.isHot === next.isHot) {
continue
}
await prisma.signal.update({
where: { id: row.id },
data: {
hotScore: next.hotScore,
isHot: next.isHot,
},
})
updated += 1
}
console.log('[signals-hot] done', {
total: rows.length,
updated,
skippedUnknownSource: skipped,
})
}
main()
.catch((error) => {
console.error('[signals-hot] failed', error)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})