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 { PrismaClient } from '@prisma/client';
|
||||||
|
import { chunk } from 'lodash-es';
|
||||||
|
|
||||||
type SessionTime = {
|
type SessionTime = {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
@@ -17,16 +18,19 @@ export class CorrectSessionUpdateTime1751966744168 {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(
|
for (const s of chunk(sessionTime, 100)) {
|
||||||
sessionTime
|
const sessions = s.filter((s): s is SessionTime => !!s._max.createdAt);
|
||||||
.filter((s): s is SessionTime => !!s._max.createdAt)
|
await db.$transaction(async tx => {
|
||||||
.map(s =>
|
await Promise.all(
|
||||||
db.aiSession.update({
|
sessions.map(s =>
|
||||||
where: { id: s.sessionId },
|
tx.aiSession.update({
|
||||||
data: { updatedAt: s._max.createdAt },
|
where: { id: s.sessionId },
|
||||||
})
|
data: { updatedAt: s._max.createdAt },
|
||||||
)
|
})
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// revert the migration
|
// revert the migration
|
||||||
|
|||||||
Reference in New Issue
Block a user