logging slow autocomplete times

This commit is contained in:
azivner 2018-11-04 22:10:52 +01:00
parent 26b9302267
commit 607c821cac

View file

@ -2,6 +2,7 @@
const noteCacheService = require('../../services/note_cache');
const repository = require('../../services/repository');
const log = require('../../services/log');
async function getAutocomplete(req) {
const query = req.query.query;
@ -9,6 +10,8 @@ async function getAutocomplete(req) {
let results;
const timestampStarted = Date.now();
if (query.trim().length === 0) {
results = await getRecentNotes(currentNoteId);
}
@ -16,6 +19,12 @@ async function getAutocomplete(req) {
results = noteCacheService.findNotes(query);
}
const msTaken = Date.now() - timestampStarted;
if (msTaken >= 100) {
log.info(`Slow autocomplete took ${msTaken}ms`);
}
return results.map(res => {
return {
value: res.path,