Skip to content

Commit

Permalink
Merge pull request #21 from ericz1803/main
Browse files Browse the repository at this point in the history
Feature: Add caching query param in cacheHandler (Fix TRAPI issue #224)
  • Loading branch information
newgene authored Jul 27, 2021
2 parents 173f34b + bfaa179 commit 9980b96
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/batch_edge_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const utils = require('./utils');
const LogEntry = require('./log_entry');

module.exports = class BatchEdgeQueryHandler {
constructor(kg, resolveOutputIDs = true) {
constructor(kg, resolveOutputIDs = true, options) {
this.kg = kg;
this.subscribers = [];
this.logs = [];
this.caching = options && options.caching;
this.resolveOutputIDs = resolveOutputIDs;
}

Expand Down Expand Up @@ -108,7 +109,7 @@ module.exports = class BatchEdgeQueryHandler {
async query(qEdges) {
const nodeUpdate = new NodesUpdateHandler(qEdges);
await nodeUpdate.setEquivalentIDs(qEdges);
const cacheHandler = new CacheHandler(qEdges);
const cacheHandler = new CacheHandler(qEdges, this.caching);
const { cachedResults, nonCachedEdges } = await cacheHandler.categorizeEdges(qEdges);
this.logs = [...this.logs, ...cacheHandler.logs];
let query_res;
Expand Down
6 changes: 4 additions & 2 deletions src/cache_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const debug = require('debug')('bte:biothings-explorer-trapi:cache_handler');
const LogEntry = require('./log_entry');

module.exports = class {
constructor(qEdges, logs = []) {
constructor(qEdges, caching, logs = []) {
this.qEdges = qEdges;
this.logs = logs;
this.cacheEnabled = !(process.env.REDIS_HOST === undefined) && !(process.env.REDIS_PORT === undefined);
this.cacheEnabled = (caching === 'false') ?
false :
(!(process.env.REDIS_HOST === undefined) && !(process.env.REDIS_PORT === undefined));
this.logs.push(
new LogEntry('DEBUG', null, `REDIS cache is ${this.cacheEnabled === true ? '' : 'not'} enabled.`).getLog(),
);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
_createBatchEdgeQueryHandlers(queryPaths, kg) {
let handlers = {};
for (const index in queryPaths) {
handlers[index] = new BatchEdgeQueryHandler(kg, this.resolveOutputIDs);
handlers[index] = new BatchEdgeQueryHandler(kg, this.resolveOutputIDs, {caching: this.options.caching});
handlers[index].setEdges(queryPaths[index]);
handlers[index].subscribe(this.queryResults);
handlers[index].subscribe(this.bteGraph);
Expand Down

0 comments on commit 9980b96

Please sign in to comment.