@@ -376,54 +376,33 @@ pointing at invalid files have also been cleaned up.")
377 // Go through every downloaded file and check if they are orphaned
377 // Go through every downloaded file and check if they are orphaned
378 for (var l = 0; l < filelist.length; l++) {
378 for (var l = 0; l < filelist.length; l++) {
379− var isOrphanFile = true
381− // Go through every podcast
382− for (var i=0; i < rs.rows.length; i++) {
383− var podcast = rs.rows.item(i);
384− var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=?", [podcast.rowid]);
379+ var rs2 = tx.executeSql("SELECT rowid FROM Episode WHERE downloadedfile = ?", [fileManager.podcastDirectory + "/" + filelist[l]])
386− // Go through every episode in the podcast
387− for (var j=0; j < rs2.rows.length; j++) {
388− var episode = rs2.rows.item(j);
389− if (episode.downloadedfile) {
390− if(fileManager.podcastDirectory + "/" + filelist[l] === episode.downloadedfile) {
391− isOrphanFile = false
397− if (isOrphanFile) {
381+ if (rs2.rows.length == 0) {
398 orphanListItem.fileCount++
382 orphanListItem.fileCount++
399 fileManager.deleteFile(fileManager.podcastDirectory + "/" + filelist[l])
383 fileManager.deleteFile(fileManager.podcastDirectory + "/" + filelist[l])
400 console.log("[LOG]: Removed Orphan File: " + fileManager.podcastDirectory + "/" + filelist[l])
384 console.log("[LOG]: Removed Orphan File: " + fileManager.podcastDirectory + "/" + filelist[l])
404− // Go through every podcast in the db and find orphaned links
388+ // Filter all episode with downloadedfile links and check if they are orphaned links or not
389+ var rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE downloadedfile IS NOT NULL")
405− for (i=0; i < rs.rows.length; i++) {
390+ for (var i=0; i<rs2.rows.length; i++) {
406 var isOrphanLink = true
391 var isOrphanLink = true
407− podcast = rs.rows.item(i);
392+ var episode = rs2.rows.item(i);
408− rs2 = tx.executeSql("SELECT rowid, * FROM Episode WHERE podcast=?", [podcast.rowid]);
410− // Go through every episode in the podcast
411− for (j=0; j < rs2.rows.length; j++) {
412− episode = rs2.rows.item(j);
413− if (episode.downloadedfile) {
414− for (l = 0; l < filelist.length; l++) {
415− if(episode.downloadedfile === fileManager.podcastDirectory + "/" + filelist[l]) {
416− isOrphanLink = false
394+ for (var l = 0; l < filelist.length; l++) {
395+ if(episode.downloadedfile === fileManager.podcastDirectory + "/" + filelist[l]) {
420− if (isOrphanLink) {
396+ isOrphanLink = false
421− orphanListItem.linkCount++
397+ break
422− tx.executeSql("UPDATE Episode SET downloadedfile = NULL WHERE guid = ?", [episode.guid]);
423− console.log("[LOG]: Removed Orphan Link: " + episode.downloadedfile)
402+ orphanListItem.linkCount++
403+ tx.executeSql("UPDATE Episode SET downloadedfile = NULL WHERE guid = ?", [episode.guid]);
404+ console.log("[LOG]: Removed Orphan Link: " + episode.downloadedfile)