Skip to content

Commit b7c7ea0

Browse files
committed
caching
1 parent 7f1f8a4 commit b7c7ea0

File tree

1 file changed

+10
-4
lines changed
  • src/server/routes/summary/entity

1 file changed

+10
-4
lines changed

src/server/routes/summary/entity/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
const _ = require('lodash');
2+
const QuickLRU = require('quick-lru');
3+
24
const { validatorGconvert } = require('../../../external-services/gprofiler/gconvert');
35
const { getEntitySummary: getNcbiGeneSummary } = require('../../../external-services/ncbi');
46
const { getEntitySummary: getHgncSummary } = require('../../../external-services/hgnc');
57
const { getEntitySummary: getUniProtSummary } = require('../../../external-services/uniprot');
6-
const { NS_HGNC_SYMBOL, NS_NCBI_GENE, NS_UNIPROT, IDENTIFIERS_URL } = require('../../../../config');
7-
8+
const { NS_HGNC_SYMBOL, NS_NCBI_GENE, NS_UNIPROT, IDENTIFIERS_URL, PC_CACHE_MAX_SIZE } = require('../../../../config');
9+
const cache = require('../../../cache');
10+
const pcCache = new QuickLRU({ maxSize: PC_CACHE_MAX_SIZE });
811
/**
912
* entityFetch: Retrieve EntitySummary for a given id from a datasource
1013
*
1114
* @param { array } localID string(s) that should be fetched
1215
* @return { object } value is EntitySummary keyed by the local ID
1316
*/
14-
const entityFetch = async ( localIds, dataSource ) => {
17+
const rawEntityFetch = async ( localIds, dataSource ) => {
1518
let eSummary;
1619
switch ( dataSource ) {
1720
case NS_HGNC_SYMBOL:
@@ -37,7 +40,7 @@ const createUri = ( namespace, localId ) => IDENTIFIERS_URL + '/' + namespace +
3740
* - query: token that has an associated NCBI Gene ID
3841
* - EntitySummary object
3942
*/
40-
const entitySearch = async tokens => {
43+
const rawEntitySearch = async tokens => {
4144

4245
const results = [];
4346

@@ -96,4 +99,7 @@ const entitySearch = async tokens => {
9699
return results;
97100
};
98101

102+
const entitySearch = cache(rawEntitySearch, pcCache);
103+
const entityFetch = cache(rawEntityFetch, pcCache);
104+
99105
module.exports = { entitySearch, entityFetch };

0 commit comments

Comments
 (0)