|
|
@@ -35,18 +35,36 @@ exports.pengajuan = handleError(async (req, res) => {
|
|
|
|
|
|
exports.dokumen = handleError(async (req, res) => {
|
|
|
const dokumen = await dokumenModel.find()
|
|
|
+ const BATCH_SIZE = 10 // Proses 10 dokumen per batch
|
|
|
+ const DELAY_MS = 100 // Delay 100ms antar batch
|
|
|
|
|
|
- if (dokumen?.length) await Promise.all(dokumen.map(async e => {
|
|
|
- const path = e.path.split('/').slice(3).join('/')
|
|
|
- await dokumenModel.findOneAndUpdate({
|
|
|
- _id: e._id
|
|
|
- }, {
|
|
|
- path: `${coba.decrypt(process.env.W8A1C)}/${path}`
|
|
|
- })
|
|
|
- }))
|
|
|
+ if (dokumen?.length) {
|
|
|
+ for (let i = 0; i < dokumen.length; i += BATCH_SIZE) {
|
|
|
+ const batch = dokumen.slice(i, i + BATCH_SIZE)
|
|
|
+
|
|
|
+ await Promise.all(
|
|
|
+ batch.map(async (e) => {
|
|
|
+ const path = `${coba.decrypt(process.env.W8A1C)}/dokumen/${e.chunk}/${e.judul}`
|
|
|
+ await dokumenModel.findOneAndUpdate(
|
|
|
+ {
|
|
|
+ _id: e._id,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ path,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ )
|
|
|
+
|
|
|
+ // Delay antar batch untuk avoid rate limit
|
|
|
+ if (i + BATCH_SIZE < dokumen.length) {
|
|
|
+ await new Promise((resolve) => setTimeout(resolve, DELAY_MS))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return response.success(res, {
|
|
|
- message: 'Berhasil migrasi dokumen'
|
|
|
+ message: `Berhasil migrasi ${dokumen?.length || 0} dokumen`,
|
|
|
})
|
|
|
})
|
|
|
|