Optimized queue.removeRange()

This commit is contained in:
rainbow napkin 2025-11-01 11:34:50 -04:00
parent c3712bfd77
commit dd36b1d923

View file

@ -360,6 +360,7 @@ class queue{
chanDB.media.liveRemainder = this.nowPlaying.uuid; chanDB.media.liveRemainder = this.nowPlaying.uuid;
//Save the chanDB //Save the chanDB
console.log("Saving db from goLive() :363");
await chanDB.save(); await chanDB.save();
} }
@ -592,8 +593,23 @@ class queue{
//For each item //For each item
for(let item of foundItems){ for(let item of foundItems){
//Remove media, passing down chanDB so we're not looking again and again //Remove media, passing down chanDB so we're not looking again and again
await this.removeMedia(item.uuid, socket, chanDB); await this.removeMedia(item.uuid, socket, chanDB, true);
//If this is the current item
if(this.nowPlaying != null && item.uuid == this.nowPlaying.uuid){
//End it
await this.end(false, true, false, chanDB);
} }
}
//Save data to channe database
await chanDB.save();
//Refresh next timer
await this.refreshNextTimer();
console.log("Saved by removeRange() :599");
}catch(err){ }catch(err){
//If this was originated by someone //If this was originated by someone
@ -788,6 +804,7 @@ class queue{
//If saving is disabled //If saving is disabled
if(!noScheduling){ if(!noScheduling){
//Save changes to the DB //Save changes to the DB
console.log("Saving db from removeMedia() :792");
await chanDB.save(); await chanDB.save();
} }
} }
@ -844,6 +861,7 @@ class queue{
//If saving is enabled (seperate from all DB transactions since caller function may want modifications but handle saving on its own) //If saving is enabled (seperate from all DB transactions since caller function may want modifications but handle saving on its own)
if(!noScheduling){ if(!noScheduling){
console.log("Saving db from removeMedia() :849");
await chanDB.save(); await chanDB.save();
} }
@ -1034,6 +1052,7 @@ class queue{
try{ try{
//If saving is enabled (seperate from all DB transactions since caller function may want modifications but handle saving on its own) //If saving is enabled (seperate from all DB transactions since caller function may want modifications but handle saving on its own)
if(!noSave){ if(!noSave){
console.log("Saving db from scheduleMedia() :1040");
//Save the database //Save the database
await chanDB.save(); await chanDB.save();
} }
@ -1130,6 +1149,9 @@ class queue{
return record.uuid != mediaObj.uuid; return record.uuid != mediaObj.uuid;
}); });
console.log("Saving db from start() :1138");
//Save the channel //Save the channel
await chanDB.save(); await chanDB.save();
@ -1264,6 +1286,9 @@ class queue{
//broadcast queue using unsaved archive, run this before chanDB.save() for better responsiveness //broadcast queue using unsaved archive, run this before chanDB.save() for better responsiveness
this.broadcastQueue(chanDB); this.broadcastQueue(chanDB);
console.log("Saving db from end() :1275");
//Save our changes to the DB //Save our changes to the DB
await chanDB.save(); await chanDB.save();
} }
@ -1293,6 +1318,7 @@ class queue{
} }
//Disable stream lock //Disable stream lock
this.streamLock = false; this.streamLock = false;
console.log("testem");
//We don't have to save here since someone else will do it for us :) //We don't have to save here since someone else will do it for us :)
//Reminder for those of us reading this in the future since I'm a dipshit: this only clears the DB liveRemainder, NOT the RAM backed variable //Reminder for those of us reading this in the future since I'm a dipshit: this only clears the DB liveRemainder, NOT the RAM backed variable
@ -1359,6 +1385,9 @@ class queue{
//Throw the livestream into the archive //Throw the livestream into the archive
chanDB.media.archived.push(wasPlaying); chanDB.media.archived.push(wasPlaying);
console.log("Saving db from livestreamOverwriteSchedule() :1373");
//Save the DB //Save the DB
await chanDB.save(); await chanDB.save();
@ -1852,6 +1881,9 @@ class queue{
//Update schedule to only contain what hasn't been played yet //Update schedule to only contain what hasn't been played yet
chanDB.media.scheduled = newSched; chanDB.media.scheduled = newSched;
console.log("Saving db from rehydrateQueue() :1869");
//Save the DB //Save the DB
await chanDB.save() await chanDB.save()