S
S
Shakir Yakubov2020-06-30 18:22:44
JavaScript
Shakir Yakubov, 2020-06-30 18:22:44

Why does the function overload all the server's RAM?

There is a code:

async function checkQuery(object) {
  i = 0;
  while (i < urls[1].length) {
    sql = 'SELECT id FROM cases WHERE case_number="' + urls[2][i] + '"';
    await connection.execute(sql, function(err, results, fields, rows) {
      //console.log('... . Ошибка: ' + err + ', Данные: ' + results[0].objid + ', мета-данные полей: ' + fields + '.');
      if(results[0] === undefined) {
        console.log('Совпадение не найдено');
        i++;
      } else {
        console.log('Такое дело есть!');
        urls[0].splice(i, 1);
        urls[1].splice(i, 1);
        urls[2].splice(i, 1);
      }
    });  
  }
  console.log(urls[2].length);
}

When it is executed, the entire server memory is loaded and it displays 'killed' in the console

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mario Kun, 2020-06-30
@marioKun

Take the sql query out of the loop
Try first to get all urls[2][i] and write them into one array (array1) so that there is a single list /
Then try to execute a query like: SELECT id FROM cases WHERE case_number in ( array1.join(' ,') )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question