From f53998f3207ebed7433451caf07debdd445929a6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 4 Oct 2024 07:42:31 +0200 Subject: [PATCH] fix: refs #7906 optimize method fix --- modules/zone/back/methods/zone/deleteZone.js | 31 +++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 4b857e30a..a1bc1d486 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -45,18 +45,33 @@ module.exports = Self => { }, }, }; - + console.time('finds'); const [ticketList, fixingState, worker] = await Promise.all([ models.Ticket.find(filter, myOptions), models.State.findOne({where: {code: 'FIXING'}}, myOptions), models.Worker.findOne({where: {id: userId}}, myOptions) ]); + console.timeEnd('finds'); - await models.Ticket.rawSql( - 'UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', - [id], - myOptions - ); + console.time('ticket update'); + console.log('ticketList: ', ticketList.length); + // await models.Ticket.rawSql( + // 'UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ? LIMIT 2000', + // [id], + // myOptions + // ); + const promises = []; + // OFFSET no li mola a mariadb + for (let i = 0; i <= 30000; i += 2000) { + promises.push(models.Ticket.rawSql( + `UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ? LIMIT 2000 OFFSET ${i};`, + [id], + myOptions + )); + } + await Promise.all(promises); + console.timeEnd('ticket update'); + /* const updatePromises = ticketList.map(ticket => { if (ticket.ticketState().alertLevel === 0) { @@ -69,8 +84,8 @@ module.exports = Self => { }); await Promise.all(updatePromises); await models.Zone.destroyById(id, myOptions); - - if (tx) await tx.commit(); + */ + if (tx) await tx.rollback(); return id; } catch (err) {