Fix Memory usage peaking during TV Guide Generation
This commit is contained in:
parent
87fb2baa73
commit
e506ac15b0
20
index.js
20
index.js
@ -67,19 +67,29 @@ let xmltvInterval = {
|
||||
interval: null,
|
||||
lastRefresh: null,
|
||||
updateXML: async () => {
|
||||
let channels = [];
|
||||
try {
|
||||
let getChannelsCached = async() => {
|
||||
let channelNumbers = await channelDB.getAllChannelNumbers();
|
||||
channels = await Promise.all( channelNumbers.map( async (x) => {
|
||||
return await channelCache.getChannelConfig(channelDB, x);
|
||||
return await Promise.all( channelNumbers.map( async (x) => {
|
||||
return (await channelCache.getChannelConfig(channelDB, x))[0];
|
||||
}) );
|
||||
}
|
||||
|
||||
let channels = [];
|
||||
|
||||
try {
|
||||
channels = await getChannelsCached();
|
||||
let xmltvSettings = db['xmltv-settings'].find()[0];
|
||||
await guideService.refresh( await channelDB.getAllChannels(), xmltvSettings.cache*60*60*1000 );
|
||||
let t = guideService.prepareRefresh(channels, xmltvSettings.cache*60*60*1000);
|
||||
channels = null;
|
||||
|
||||
await guideService.refresh(t);
|
||||
xmltvInterval.lastRefresh = new Date()
|
||||
console.log('XMLTV Updated at ', xmltvInterval.lastRefresh.toLocaleString());
|
||||
} catch (err) {
|
||||
console.error("Unable to update TV guide?", err);
|
||||
return;
|
||||
}
|
||||
channels = await getChannelsCached();
|
||||
|
||||
let plexServers = db['plex-servers'].find()
|
||||
for (let i = 0, l = plexServers.length; i < l; i++) { // Foreach plex server
|
||||
|
||||
@ -28,12 +28,16 @@ class TVGuideService
|
||||
return this.cached;
|
||||
}
|
||||
|
||||
async refresh(inputChannels, limit) {
|
||||
prepareRefresh(inputChannels, limit) {
|
||||
let t = (new Date()).getTime();
|
||||
this.updateTime = t;
|
||||
this.updateLimit = t + limit;
|
||||
let channels = inputChannels;
|
||||
this.updateChannels = channels;
|
||||
return t;
|
||||
}
|
||||
|
||||
async refresh(t) {
|
||||
while( this.lastUpdate < t) {
|
||||
if (this.currentUpdate == -1) {
|
||||
this.currentUpdate = this.updateTime;
|
||||
@ -47,6 +51,9 @@ class TVGuideService
|
||||
}
|
||||
|
||||
async makeAccumulated(channel) {
|
||||
if (typeof(channel.programs) === 'undefined') {
|
||||
throw Error( JSON.stringify(channel).slice(0,200) );
|
||||
}
|
||||
let n = channel.programs.length;
|
||||
let arr = new Array( channel.programs.length + 1);
|
||||
arr[0] = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user