Skip to content

Commit

Permalink
add querycache to Backlog for faster search
Browse files Browse the repository at this point in the history
  • Loading branch information
alihm committed Jul 14, 2023
1 parent 139300d commit 6f92419
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ClusterOperator/Backlog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-else-return */
/* eslint-disable no-restricted-syntax */
// const timer = require('timers/promises');
const queryCache = require('memory-cache');
const dbClient = require('./DBClient');
const config = require('./config');
const log = require('../lib/log');
Expand All @@ -24,6 +25,8 @@ class BackLog {

static executeLogs = true;

static BLqueryCache = queryCache;

/**
* [createBacklog]
* @param {object} params [description]
Expand Down Expand Up @@ -113,6 +116,9 @@ class BackLog {
[seqForThis, query, timestamp],
);
if (this.executeLogs) log.info(`executed ${seqForThis}`);
this.BLqueryCache.put(seqForThis, {
query, seq: seqForThis, timestamp, connId, ip: false,
}, 1000 * 30);
this.writeLock = false;
let result = null;
if (connId === false) {
Expand Down
6 changes: 5 additions & 1 deletion ClusterOperator/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ async function initServer() {
socket.emit('query', record.query, record.seq, record.timestamp, connId);
} else {
log.warn(`query ${index} not in query cache`, 'red');
const BLRecord = await BackLog.getLog(index);
let BLRecord = BackLog.BLqueryCache.get(index);
log.info(JSON.stringify(BLRecord), 'red');
if (!BLRecord) {
BLRecord = BackLog.getLog(index);
log.info(`from DB : ${JSON.stringify(BLRecord)}`, 'red');
}
}
// if (record) {

Expand Down

0 comments on commit 6f92419

Please sign in to comment.