Skip to content

Commit

Permalink
Set a timeout for text search after which results so far are returned
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Mar 12, 2019
1 parent d268bc7 commit 6045c70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"deproxifyURLs": false, // Automatically try deproxified versions of URLs
"identifierSearchLambda": "", // Identifier search Lambda function for text search
"port": 1969,
"textSearchTimeout": 5,
"translators": {
"CrossrefREST.email": "" // Pass an email to Crossref REST API to utilize the faster servers pool
},
Expand Down
8 changes: 8 additions & 0 deletions src/textSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ module.exports = {


async function search(query, start) {
const timeout = config.get('textSearchTimeout') * 1000;
const startTime = new Date();
const numResults = 3;
let identifiers;
let moreResults = false;
Expand Down Expand Up @@ -164,6 +166,9 @@ async function search(query, start) {
translate.setIdentifier(identifier);
let translators = await translate.getTranslators();
if (!translators.length) {
if (new Date() > startTime.getTime() + timeout) {
break;
}
continue;
}
translate.setTranslator(translators);
Expand Down Expand Up @@ -191,6 +196,9 @@ async function search(query, start) {
Zotero.debug(e, 1);
}
}
if (new Date() > startTime.getTime() + timeout) {
break;
}
}

return {
Expand Down

0 comments on commit 6045c70

Please sign in to comment.