Browse Source

updated comments, cleaned up conditionals flow

query-for-venues-on-admin-only
Stephen Hess 7 years ago
parent
commit
8e953c60e1
  1. 72
      controller/search_with_appending_results.js

72
controller/search_with_appending_results.js

@ -70,51 +70,47 @@ function setup( apiConfig, esclient, query, should_execute ){
return; return;
} }
// if execution has gotten this far then one of three things happened: // error handler, return immediately
// - the request didn't time out
// - maxRetries has been hit so we're giving up
// - another error occurred
// in either case, handle the error or results
// error handler
if( err ){ if( err ){
if (_.isObject(err) && err.message) { req.errors.push(_.defaultTo(err.message, err));
req.errors.push( err.message ); return;
} else { }
req.errors.push( err );
} // if execution has gotten this far then one of three things happened:
// - success! (the request didn't time out)
// - maxRetries has been hit so we're giving up (too many timeouts),
// docs will be empty
// log that a retry was successful
// most requests succeed on first attempt so this declutters log files
if (currentAttempt > 1) {
logger.info(`succeeded on retry ${currentAttempt-1}`);
} }
// set response data
else {
// log that a retry was successful
// most requests succeed on first attempt so this declutters log files
if (currentAttempt > 1) {
logger.info(`succeeded on retry ${currentAttempt-1}`);
}
const messageParts = [ const messageParts = [
'[controller:search]', '[controller:search]',
`[queryType:${renderedQuery.type}]`, `[queryType:${renderedQuery.type}]`,
`[es_result_count:${_.defaultTo(docs, []).length}]` `[es_result_count:${_.defaultTo(docs, []).length}]`
]; ];
// if there are docs, concatenate them onto the end of existing results // if there are docs, concatenate them onto the end of existing results
if (docs) { if (docs) {
res.data = _.concat(_.defaultTo(res.data, []), docs); res.data = _.concat(_.defaultTo(res.data, []), docs);
}
res.meta = meta || {};
// store the query_type for subsequent middleware
res.meta.query_type = renderedQuery.type;
logger.info(messageParts.join(' '));
debugLog.push(req, {queryType: {
[renderedQuery.type] : {
es_result_count: parseInt(messageParts[2].slice(17, -1))
}
}});
} }
res.meta = meta || {};
// store the query_type for subsequent middleware
res.meta.query_type = renderedQuery.type;
logger.info(messageParts.join(' '));
debugLog.push(req, {queryType: {
[renderedQuery.type] : {
es_result_count: parseInt(messageParts[2].slice(17, -1))
}
}});
logger.debug('[ES response]', docs); logger.debug('[ES response]', docs);
next(); next();
}); });
debugLog.stopTimer(req, initialTime); debugLog.stopTimer(req, initialTime);
}); });

Loading…
Cancel
Save