SEARCH-438

- Implemented the real-time indexing in a queue and flush
This commit is contained in:
Keerthi Niranjan
2017-11-20 12:01:30 +05:30
parent 6b1cb11db7
commit 1cbc443024
4 changed files with 117 additions and 23 deletions

39
js/search/queue.js Normal file
View File

@@ -0,0 +1,39 @@
let messagesData = [];
let makeBoundTimedCollector = function(isIndexing, timeout, callback) {
let timer;
return function (...args) {
if (!timer){
timer = setTimeout(function(){
if (!isIndexing) {
flush(getQueue())
}
}, timeout);
}
let queue = getQueue();
queue.push(args[0]);
if (!isIndexing()) {
flush(queue);
}
};
function flush(queue) {
clearTimeout(timer);
timer = null;
resetQueue();
callback(JSON.stringify(queue));
}
function getQueue(){
return messagesData
}
function resetQueue(){
messagesData = []
}
};
module.exports = makeBoundTimedCollector;