На сколько я могу предположить, у вас несколько Promise.all([clearTempLOOT(), clearAll_prices()]) одновременно срабатывает.Тут запрос идёт к двум разным таблицам: к таблице temp_loot и к таблице all_prices.
Складывал бы все записи во временную таблицу
INSERT INTO all_prices(name, price_loot, have_loot, max_loot, updated_loot) (SELECT name, price_loot, have_loot, max_loot, updated_loot FROM `temp_loot` WHERE name NOT IN (SELECT name FROM `all_prices`));
update all_prices a set a.relevant_loot = 0 where a.name in (SELECT name FROM (select * from all_prices) as t1 WHERE name NOT IN (SELECT t.name FROM temp_loot t));
pool.getConnection(function (err, connection) {
function clearTempLOOT() {
return new Promise((resolveDB, rejectDB) => {
connection.query('DELETE FROM temp_loot', function (e, results, fields) {
if (e) {
log.error(e);
return rejectDB();
}
else {
return resolveDB();
}
});
})
}
function clearAll_prices() {
return new Promise((resolveDB, rejectDB) => {
connection.query('update all_prices set have_loot = 0 where price_loot is not null', function (e, results, fields) {
if (e) {
log.error(e);
return rejectDB('er2');
}
else {
return resolveDB();
}
});
})
}
function fillTempLOOT() {
return new Promise((resolveDB, rejectDB) => {
connection.query('INSERT INTO temp_loot (name, price_loot, have_loot, max_loot,updated_loot) VALUES ?', [arrDB], function (e, results, fields) {
if (e) {
log.error(e);
return rejectDB();
}
else {
return resolveDB();
}
});
})
}
function addToAll_prices() {
return new Promise((resolveDB, rejectDB) => {
connection.query("INSERT INTO all_prices(name, price_loot, have_loot, max_loot, updated_loot) (SELECT name, price_loot, have_loot, max_loot, updated_loot FROM `temp_loot` WHERE name NOT IN (SELECT name FROM `all_prices`));", (e, val) => {
if (e) {
log.error(e);
return rejectDB();
}
else {
s = val;
return resolveDB();
}
});
})
}
function replaceNotRelevant() {
return new Promise((resolveDB, rejectDB) => {
connection.query("update all_prices a set a.relevant_loot = 0 where a.name in (SELECT name FROM (select * from all_prices) as t1 WHERE name NOT IN (SELECT t.name FROM temp_loot t)); ", (e, val) => {
if (e) {
log.error(e);
return rejectDB();
}
else {
log.info('Replaced %s prices', val.changedRows);
return resolveDB();
}
});
})
}
function replaceNewPrice() {
return new Promise((resolveDB, rejectDB) => {
connection.query("UPDATE all_prices a inner JOIN temp_loot t ON t.name = a.name SET a.price_loot = t.price_loot, a.have_loot = t.have_loot, a.max_loot = t.max_loot, a.updated_loot = t.updated_loot, a.relevant_loot = 1 where a.name is not null", (e, val) => {
connection.release();
if (e) {
log.error(e);
return rejectDB();
}
else {
log.info('Replaced %s prices', val.changedRows);
return resolveDB();
}
});
})
}
Promise.all([clearTempLOOT(), clearAll_prices()])
.then(result => {
return fillTempLOOT();
})
.then(result => {
return addToAll_prices();
})
.then(result => {
return replaceNotRelevant();
})
.then(result => {
return replaceNewPrice();
})
.then(result => {
log.info('Loot db synced');
return resolve();
})
.catch(error => {
connection.release();
log.error(error);
return reject(error);
});
});
INSERT INTO all_prices(name, price_loot, have_loot, max_loot, updated_loot) (SELECT name, price_loot, have_loot, max_loot, updated_loot FROM `temp_loot` WHERE name NOT IN (SELECT name FROM `all_prices`));
Спасибо