0

I have a node app using ArangoDB and I noticed tons of repeated entries in the logs when I query. I can't tell if its doing multiple requests, or just logging repeatedly.

I'm calling this from my Hapi.js handler which is an async function

let user = await arango.getUser('user1');

and this is the function

exports.getUser = function(name) {
  return new Promise(function(fulfill, reject) {
    let query = `FOR u IN users FILTER u._key == '${name}' RETURN u`
    db.query(query).then(user => {
      logger.debug(`Retrieved user '${name}' successfully.`);
      fulfill(user._result[0]);
    }).catch(err => {
      logger.error(`Failed to query for user '${name}'`);
      reject();
    });
  });
}

It fulfills a single result but the log looks like this on a single page load. It's always 16 times.

2018-08-03T01:33:17.922Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:17.925Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.006Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.027Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.030Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.036Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.041Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.042Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.045Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.046Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.053Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.057Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.058Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.147Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.204Z debug: Retrieved user 'user1' successfully.
2018-08-03T01:33:18.293Z debug: Retrieved user 'user1' successfully.

I'm not sure how to debug this to see how many times Arango is actually queried or if it's executing the code within the .then() while waiting for the promise to resolve. I've never seen this behavior before. I'm running Arango in Docker on my MacBook and Node right in terminal. if its not actually executing the query 16 times and is just a benign side effect of the async function then thats fine, I just want to be sure I'm not doing something wrong here. Thanks for the help.

edit: upon additional testing, if the function is called outside of the Hapi.js handler, not during a page load, the log only pops once.

Michael
  • 23
  • 1
  • 7

0 Answers0