cron update/fix, limit video.delete queries to 1 row

merge-requests/7/head
Moe 2018-06-20 22:45:07 -07:00
parent 8ef9e55f58
commit bfef5eecb0
2 changed files with 45 additions and 30 deletions

View File

@ -900,12 +900,16 @@ s.video=function(x,e,k){
}else{
time = e.time
}
time = new Date(time)
if(config.databaseType !== 'sqlite'){
time = moment(time).format('YYYY-MM-DD HH:mm:ss')
}
e.save=[e.id,e.ke,time];
s.sqlQuery('SELECT * FROM Videos WHERE `mid`=? AND `ke`=? AND `time`=?',e.save,function(err,r){
s.sqlQuery('SELECT * FROM Videos WHERE `mid`=? AND `ke`=? AND `time`=? LIMIT 1',e.save,function(err,r){
if(r&&r[0]){
r=r[0]
var dir=s.video('getDir',r)
s.sqlQuery('DELETE FROM Videos WHERE `mid`=? AND `ke`=? AND `time`=?',e.save,function(){
s.sqlQuery('DELETE FROM Videos WHERE `mid`=? AND `ke`=? AND `time`=? LIMIT 1',e.save,function(){
fs.stat(dir+filename,function(err,file){
if(err){
s.systemLog('File Delete Error : '+e.ke+' : '+' : '+e.mid,err)
@ -916,7 +920,8 @@ s.video=function(x,e,k){
s.file('delete',dir+filename)
})
}else{
console.log(e)
// console.log('Delete Failed',e)
// console.error(err)
}
})
break;

60
cron.js
View File

@ -177,9 +177,9 @@ s.checkFilterRules=function(v,callback){
}
//delete old videos with filter
if(config.cron.deleteOld===true){
v.d.filters.deleteOldByCron={
"id":"deleteOldByCron",
"name":"deleteOldByCron",
v.d.filters.deleteOldVideosByCron={
"id":"deleteOldVideosByCron",
"name":"deleteOldVideosByCron",
"sort_by":"time",
"sort_by_direction":"ASC",
"limit":"",
@ -227,6 +227,9 @@ s.checkFilterRules=function(v,callback){
}
s.sqlQuery('SELECT * FROM Videos '+b.sql,b.ar,function(err,r){
if(r&&r[0]){
if(r.length > 0 || config.debugLog === true){
s.cx({f:'filterMatch',msg:r.length+' SQL rows match "'+m+'"',ke:v.ke,time:moment()})
}
b.cx={
f:'filters',
name:b.name,
@ -237,11 +240,9 @@ s.checkFilterRules=function(v,callback){
};
if(b.archive==="1"){
s.cx({f:'filters',ff:'archive',videos:r,time:moment(),ke:v.ke,id:b.id});
}else{
if(b.delete==="1"){
}else if(b.delete==="1"){
s.cx({f:'filters',ff:'delete',videos:r,time:moment(),ke:v.ke,id:b.id});
}
}
if(b.email==="1"){
b.cx.ff='email';
b.cx.delete=b.delete;
@ -281,21 +282,30 @@ s.deleteRowsWithNoVideo=function(v,callback){
if(evs&&evs[0]){
es.del=[];es.ar=[v.ke];
evs.forEach(function(ev){
var details = JSON.parse(ev.details)
var filename = ev.time
var dir = s.getVideoDirectory(ev)+s.moment(filename)+'.'+ev.ext;
var fileExists = fs.existsSync(dir)
if(details.isUTC === true){
filename = s.localToUtc(filename).format('YYYY-MM-DDTHH-mm-ss')
dir = s.getVideoDirectory(ev)+filename+'.'+ev.ext;
fileExists = fs.existsSync(dir)
var filename
var details
try{
details = JSON.parse(ev.details)
}catch(err){
if(details instanceof Object){
details = ev.details
}else{
details = {}
}
}
var dir = s.getVideoDirectory(ev)
if(details.isUTC === true){
filename = s.localToUtc(ev.time).format('YYYY-MM-DDTHH-mm-ss')+'.'+ev.ext
}else{
filename = s.moment(ev.time)+'.'+ev.ext
}
fileExists = fs.existsSync(dir+filename)
if(fileExists !== true){
s.video('delete',ev)
s.tx({f:'video_delete',filename:filename+'.'+ev.ext,mid:ev.mid,ke:ev.ke,time:ev.time,end:s.moment(new Date,'YYYY-MM-DD HH:mm:ss')},'GRP_'+ev.ke);
}
});
if(es.del.length>0){
if(es.del.length>0 || config.debugLog === true){
s.cx({f:'deleteNoVideo',msg:es.del.length+' SQL rows with no file deleted',ke:v.ke,time:moment()})
}
}
@ -314,8 +324,8 @@ s.deleteOldLogs=function(v,callback){
s.sqlQuery("DELETE FROM Logs WHERE ke=? AND `time` < "+s.sqlDate('? DAYS'),[v.ke,v.d.log_days],function(err,rrr){
callback()
if(err)return console.error(err);
if(rrr.affectedRows && rrr.affectedRows.length>0){
s.cx({f:'deleteLogs',msg:rrr.affectedRows+' SQL rows older than '+v.d.log_days+' days deleted',ke:v.ke,time:moment()})
if(rrr.affectedRows && rrr.affectedRows.length>0 || config.debugLog === true){
s.cx({f:'deleteLogs',msg:(rrr.affectedRows || 0)+' SQL rows older than '+v.d.log_days+' days deleted',ke:v.ke,time:moment()})
}
})
}else{
@ -329,8 +339,8 @@ s.deleteOldEvents=function(v,callback){
s.sqlQuery("DELETE FROM Events WHERE ke=? AND `time` < "+s.sqlDate('? DAYS'),[v.ke,v.d.event_days],function(err,rrr){
callback()
if(err)return console.error(err);
if(rrr.affectedRows && rrr.affectedRows.length>0){
s.cx({f:'deleteEvents',msg:rrr.affectedRows+' SQL rows older than '+v.d.event_days+' days deleted',ke:v.ke,time:moment()})
if(rrr.affectedRows && rrr.affectedRows.length>0 || config.debugLog === true){
s.cx({f:'deleteEvents',msg:(rrr.affectedRows || 0)+' SQL rows older than '+v.d.event_days+' days deleted',ke:v.ke,time:moment()})
}
})
}else{
@ -354,8 +364,8 @@ s.deleteOldFileBins=function(v,callback){
s.sqlQuery("DELETE"+fileBinQuery,[v.ke,v.d.fileBin_days],function(err,rrr){
callback()
if(err)return console.error(err);
if(rrr.affectedRows && rrr.affectedRows.length>0){
s.cx({f:'deleteFileBins',msg:rrr.affectedRows+' files older than '+v.d.fileBin_days+' days deleted',ke:v.ke,time:moment()})
if(rrr.affectedRows && rrr.affectedRows.length>0 || config.debugLog === true){
s.cx({f:'deleteFileBins',msg:(rrr.affectedRows || 0)+' files older than '+v.d.fileBin_days+' days deleted',ke:v.ke,time:moment()})
}
})
}else{
@ -370,7 +380,7 @@ s.deleteOldFileBins=function(v,callback){
s.checkForOrphanedFiles=function(v,callback){
if(config.cron.deleteOrphans===true){
var finish=function(count){
if(count>0){
if(count>0 || config.debugLog === true){
s.cx({f:'deleteOrphanedFiles',msg:count+' SQL rows with no database row deleted',ke:v.ke,time:moment()})
}
callback()
@ -449,9 +459,9 @@ s.processUser = function(number,rows){
rr.forEach(function(b,m){
b.details=JSON.parse(b.details);
if(b.details.max_keep_days&&b.details.max_keep_days!==''){
v.d.filters['deleteOldByCron'+b.mid]={
"id":'deleteOldByCron'+b.mid,
"name":'deleteOldByCron'+b.mid,
v.d.filters['deleteOldVideosByCron'+b.mid]={
"id":'deleteOldVideosByCron'+b.mid,
"name":'deleteOldVideosByCron'+b.mid,
"sort_by":"time",
"sort_by_direction":"ASC",
"limit":"",