Fix throttler bug
This commit is contained in:
parent
1e72f73543
commit
0ad1b16369
@ -3,7 +3,7 @@ module.exports = {
|
||||
TVGUIDE_MAXIMUM_PADDING_LENGTH_MS: 30*60*1000,
|
||||
DEFAULT_GUIDE_STEALTH_DURATION: 5 * 60* 1000,
|
||||
TVGUIDE_MAXIMUM_FLEX_DURATION : 6 * 60 * 60 * 1000,
|
||||
TOO_FREQUENT: 100,
|
||||
TOO_FREQUENT: 1000,
|
||||
|
||||
VERSION_NAME: "1.4.6-development"
|
||||
}
|
||||
|
||||
@ -15,29 +15,38 @@ function equalItems(a, b) {
|
||||
|
||||
|
||||
function wereThereTooManyAttempts(sessionId, lineupItem) {
|
||||
let obj = cache[sessionId];
|
||||
|
||||
let t1 = (new Date()).getTime();
|
||||
if (typeof(obj) === 'undefined') {
|
||||
|
||||
let previous = cache[sessionId];
|
||||
if (typeof(previous) === 'undefined') {
|
||||
previous = cache[sessionId] = {
|
||||
t0: t1 - constants.TOO_FREQUENT * 5
|
||||
t0: t1 - constants.TOO_FREQUENT * 5,
|
||||
lineupItem: null,
|
||||
};
|
||||
|
||||
} else {
|
||||
clearTimeout(obj.timer);
|
||||
}
|
||||
previous.timer = setTimeout( () => {
|
||||
cache[sessionId].timer = null;
|
||||
delete cache[sessionId];
|
||||
}, constants.TOO_FREQUENT*5 );
|
||||
|
||||
|
||||
let result = false;
|
||||
|
||||
if (previous.t0 + constants.TOO_FREQUENT >= t1) {
|
||||
if (t1 - previous.t0 < constants.TOO_FREQUENT) {
|
||||
//certainly too frequent
|
||||
result = equalItems( previous.lineupItem, lineupItem );
|
||||
}
|
||||
cache[sessionId].t0 = t1;
|
||||
cache[sessionId].lineupItem = lineupItem;
|
||||
|
||||
cache[sessionId] = {
|
||||
t0: t1,
|
||||
lineupItem : lineupItem,
|
||||
};
|
||||
|
||||
setTimeout( () => {
|
||||
if (
|
||||
(typeof(cache[sessionId]) !== 'undefined')
|
||||
&&
|
||||
(cache[sessionId].t0 === t1)
|
||||
) {
|
||||
delete cache[sessionId];
|
||||
}
|
||||
}, constants.TOO_FREQUENT * 5 );
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@ -300,6 +300,7 @@ function video( channelDB , fillerDB, db) {
|
||||
channelCache.recordPlayback(channel.number, t0, lineupItem);
|
||||
}
|
||||
if (wereThereTooManyAttempts(session, lineupItem)) {
|
||||
console.error("There are too many attempts to play the same item in a short period of time, playing the error stream instead.");
|
||||
lineupItem = {
|
||||
isOffline: true,
|
||||
err: Error("Too many attempts, throttling.."),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user