Skip to content

Commit d44bcbd

Browse files
committed
feat: migrate activity page
1 parent 87f3414 commit d44bcbd

4 files changed

Lines changed: 36 additions & 22 deletions

File tree

components/activity/Container.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const { data, status } = await useFetch('/api/activity', {
5454
<KunLink
5555
underline="none"
5656
color="default"
57-
:to="
58-
activity.tid ? `/topic/${activity.tid}` : `/galgame/${activity.gid}`
59-
"
57+
:to="activity.link"
6058
class-name="hover:text-primary line-clamp-3 break-all transition-colors"
6159
>
6260
{{ activity.content }}
@@ -66,13 +64,13 @@ const { data, status } = await useFetch('/api/activity', {
6664
<KunLink
6765
underline="none"
6866
color="default"
69-
:to="`/user/${activity.uid}/info`"
67+
:to="`/user/${activity.user.id}/info`"
7068
class-name="hover:text-foreground text-default-500 text-sm font-medium transition-colors"
7169
>
72-
{{ activity.name }}
70+
{{ activity.user.name }}
7371
</KunLink>
7472
<span class="text-default-500 text-sm">
75-
{{ formatTimeDifference(activity.time) }}
73+
{{ formatTimeDifference(activity.created) }}
7674
</span>
7775
</div>
7876
</div>

migrate/migrateData.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -664,39 +664,56 @@ async function migrateGalgames() {
664664
async function migrateMessages() {
665665
console.log('\n🚀 Starting Message migration...')
666666

667-
// 1. 预加载所有有效的用户ID到一个Set中,用于快速查找
668-
console.log(' Fetching all valid user IDs from target database...')
669-
const users = await prisma.user.findMany({
670-
select: {
671-
id: true // 只需要id字段
672-
}
673-
})
667+
// 1. 预加载所有有效的用户ID、Topic ID 和 Galgame ID 到 Set 中,用于快速查找
668+
console.log(' Fetching all valid IDs from target database...')
669+
670+
// 获取用户ID
671+
const users = await prisma.user.findMany({ select: { id: true } })
674672
const validUserIds = new Set(users.map((u) => u.id))
675673
console.log(` ... Found ${validUserIds.size} valid users.`)
676674

675+
// 获取 Topic ID
676+
const topics = await prisma.topic.findMany({ select: { id: true } })
677+
const validTopicIds = new Set(topics.map((t) => t.id))
678+
console.log(` ... Found ${validTopicIds.size} valid topics.`)
679+
680+
// 获取 Galgame ID
681+
const galgames = await prisma.galgame.findMany({ select: { id: true } })
682+
const validGalgameIds = new Set(galgames.map((g) => g.id))
683+
console.log(` ... Found ${validGalgameIds.size} valid galgames.`)
684+
677685
const total = await MessageModel.countDocuments()
678686
const cursor = MessageModel.find().lean().cursor()
679687

680688
let migratedCount = 0
681-
let skippedCount = 0 // 新增一个计数器,用于记录跳过的消息
689+
let skippedCount = 0
682690
let batch: Prisma.messageCreateManyArgs['data'] = []
683691

684692
for await (const doc of cursor) {
685-
// 2. 在内存中校验 sender_id 和 receiver_id 是否有效
693+
// 2. 校验 sender_id 和 receiver_id 是否有效
686694
if (
695+
!doc.sender_uid ||
696+
!doc.receiver_uid ||
687697
!validUserIds.has(doc.sender_uid) ||
688698
!validUserIds.has(doc.receiver_uid)
689699
) {
690700
skippedCount++
691-
continue // 跳过这条消息
701+
continue // 如果发送者或接收者ID为空或无效,则跳过
692702
}
693703

694-
// 如果 sender_uid 或 receiver_uid 为空也跳过 (可选的额外健壮性检查)
695-
if (!doc.sender_uid || !doc.receiver_uid) {
704+
// 3. 校验 tid 和 gid 是否有效
705+
// 只有当 tid 或 gid 存在时,才进行校验。如果它们都为 null/undefined,则消息本身与 topic/galgame 无关,应该被迁移。
706+
// 如果 tid 存在,但它不在有效的 Topic ID 集合中,则跳过。
707+
if (doc.tid && !validTopicIds.has(doc.tid)) {
696708
skippedCount++
697709
continue
698710
}
699-
711+
// 如果 gid 存在,但它不在有效的 Galgame ID 集合中,则跳过。
712+
if (doc.gid && !validGalgameIds.has(doc.gid)) {
713+
skippedCount++
714+
continue
715+
}
716+
// 只有通过所有校验的消息才会进入这里
700717
const link = doc.gid ? `/galgame/${doc.gid}` : `/topic/${doc.tid}`
701718

702719
batch.push({
@@ -731,7 +748,6 @@ async function migrateMessages() {
731748
`✅ Message migration complete. Total migrated: ${migratedCount}. Total skipped: ${skippedCount}.`
732749
)
733750
}
734-
735751
async function migrateSystemMessages() {
736752
console.log('\n🚀 Starting System Message (MessageAdmin) migration...')
737753
const total = await MessageAdminModel.countDocuments()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kun-galgame-nuxt3",
3-
"version": "4.0.17",
3+
"version": "4.0.18",
44
"packageManager": "pnpm@10.4.1",
55
"private": true,
66
"scripts": {

validations/activity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { KUN_ALLOWED_ACTIVITY_TYPE } from '~/constants/activity'
33

44
export const getActivitySchema = z.object({
55
page: z.coerce.number().min(1).max(9999999),
6-
limit: z.coerce.number().min(1).max(30),
6+
limit: z.coerce.number().min(1).max(50),
77
type: z.enum(KUN_ALLOWED_ACTIVITY_TYPE)
88
})

0 commit comments

Comments
 (0)