mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(server): chunk session in migration (#13107)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved the process for updating session records to handle them in smaller batches, enhancing reliability and performance during data updates. No changes to user-facing features. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { chunk } from 'lodash-es';
|
||||
|
||||
type SessionTime = {
|
||||
sessionId: string;
|
||||
@@ -17,16 +18,19 @@ export class CorrectSessionUpdateTime1751966744168 {
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
sessionTime
|
||||
.filter((s): s is SessionTime => !!s._max.createdAt)
|
||||
.map(s =>
|
||||
db.aiSession.update({
|
||||
where: { id: s.sessionId },
|
||||
data: { updatedAt: s._max.createdAt },
|
||||
})
|
||||
)
|
||||
);
|
||||
for (const s of chunk(sessionTime, 100)) {
|
||||
const sessions = s.filter((s): s is SessionTime => !!s._max.createdAt);
|
||||
await db.$transaction(async tx => {
|
||||
await Promise.all(
|
||||
sessions.map(s =>
|
||||
tx.aiSession.update({
|
||||
where: { id: s.sessionId },
|
||||
data: { updatedAt: s._max.createdAt },
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// revert the migration
|
||||
|
||||
Reference in New Issue
Block a user