Skip to content

Commit

Permalink
#212 optimized podcasts channel deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
kagemomiji committed Dec 6, 2023
1 parent 7172810 commit bac3668
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public MediaFile getMediaFile(Path fullPath) {

// This may be an expensive op
public MediaFile getMediaFile(Path fullPath, boolean minimizeDiskAccess) {
if (Objects.isNull(fullPath)) return null;
MusicFolder folder = mediaFolderService.getMusicFolderForFile(fullPath, true, true);
if (folder == null) {
// can't look outside folders and not present in folder
Expand Down Expand Up @@ -1510,7 +1511,7 @@ public void markNonPresent(Instant lastScanned) {
* @param file media file to delete
* @return deleted media file
*/
private MediaFile delete(MediaFile file) {
public MediaFile delete(MediaFile file) {
if (file == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,23 @@ public PodcastEpisode updateEpisode(PodcastEpisode episode) {
*/
public boolean deleteChannel(int channelId) {
// Delete all associated episodes (in case they have files that need to be deleted).
getEpisodes(channelId).parallelStream().forEach(ep -> deleteEpisode(ep, false));

return podcastChannelRepository.findById(channelId).map(channel -> {
podcastEpisodeRepository.findByChannel(channel).parallelStream()
.filter(filterAllowed)
.forEach(episode -> {
MediaFile mediaFile = episode.getMediaFile();
if (mediaFile != null) {
FileUtil.delete(mediaFile.getFullPath());
mediaFileService.delete(mediaFile);
}
});
MediaFile mediaFile = channel.getMediaFile();
FileUtil.delete(mediaFile.getFullPath());
mediaFileService.refreshMediaFile(mediaFile);
podcastChannelRepository.delete(channel);
return true;
}).orElse(false);

}

/**
Expand Down
4 changes: 2 additions & 2 deletions airsonic-main/src/main/webapp/WEB-INF/jsp/podcastChannels.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@
onPlayEpisode(newestPodcastTable.row( $(this).parents('tr') ).data().id);
} );
$("#newestPodcastTable tbody").on( "click", ".addSongLast", function () {
onAddLastMediaFile(newestPodcastTable.row( $(this).parents('tr') ).data().mediaFileId);
onAddLastMediaFile(newestPodcastTable.row( $(this).parents('tr') ).data().mediaFile.id);
} );
$("#newestPodcastTable tbody").on( "click", ".addSongNext", function () {
onAddNextMediaFile(newestPodcastTable.row( $(this).parents('tr') ).data().mediaFileId);
onAddNextMediaFile(newestPodcastTable.row( $(this).parents('tr') ).data().mediaFile.id);
} );
$(".newestPodcastSelectAll").on( "change", function (e) {
selectAll(newestPodcastTable, e.target.checked);
Expand Down

0 comments on commit bac3668

Please sign in to comment.