Skip to content

Commit

Permalink
#212 change retrieve mediafile methods in SearchServiceUtilities
Browse files Browse the repository at this point in the history
  • Loading branch information
kagemomiji committed Nov 30, 2023
1 parent 34f8ccc commit 2e2fc59
Showing 1 changed file with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.airsonic.player.domain.SearchResult;
import org.airsonic.player.repository.AlbumRepository;
import org.airsonic.player.repository.ArtistRepository;
import org.airsonic.player.service.MediaFileService;
import org.airsonic.player.repository.MediaFileRepository;
import org.apache.lucene.document.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -38,8 +38,6 @@
import java.util.function.BiConsumer;
import java.util.function.Function;

import static org.springframework.util.ObjectUtils.isEmpty;

/**
* Termination used by SearchService.
*
Expand All @@ -62,14 +60,9 @@ public class SearchServiceUtilities {
@Autowired
private AlbumRepository albumRepository;

/*
* Search by id only.
* Although there is no influence at present,
* mediaFileService has a caching mechanism.
* Service is used instead of Dao until you are sure you need to use mediaFileDao.
*/
/* Search by id only. */
@Autowired
private MediaFileService mediaFileService;
private MediaFileRepository mediaFileRepository;

public final Function<Long, Integer> round = (i) -> {
// return
Expand All @@ -83,10 +76,7 @@ public class SearchServiceUtilities {

public final BiConsumer<List<MediaFile>, Integer> addMediaFileIfAnyMatch = (dist, id) -> {
if (!dist.stream().anyMatch(m -> id.equals(m.getId()))) {
MediaFile mediaFile = mediaFileService.getMediaFile(id);
if (!isEmpty(mediaFile)) {
dist.add(mediaFile);
}
mediaFileRepository.findById(id).ifPresent(file -> dist.add(file));
}
};

Expand Down Expand Up @@ -128,9 +118,10 @@ public class SearchServiceUtilities {

public final boolean addMediaFileIgnoreNull(Collection<MediaFile> collection, IndexType indexType, int subjectId) {
if (indexType == IndexType.ALBUM || indexType == IndexType.SONG) {
MediaFile mediaFile = mediaFileService.getMediaFile(subjectId);
if (mediaFile != null) {
collection.add(mediaFile);
if (mediaFileRepository.findById(subjectId).map(m -> {
collection.add(m);
return m;
}).isPresent()) {
return true;
}
}
Expand All @@ -148,10 +139,7 @@ public final boolean addAlbumIgnoreNull(Collection<Album> collection, IndexType

public final <T> void addIgnoreNull(ParamSearchResult<T> dist, IndexType indexType, int subjectId, Class<T> subjectClass) {
if (indexType == IndexType.SONG) {
MediaFile mediaFile = mediaFileService.getMediaFile(subjectId);
if (mediaFile != null) {
dist.getItems().add(subjectClass.cast(mediaFile));
}
mediaFileRepository.findById(subjectId).ifPresent(file -> dist.getItems().add(subjectClass.cast(file)));
} else if (indexType == IndexType.ARTIST_ID3) {
artistRepository.findById(subjectId).ifPresent(artist -> dist.getItems().add(subjectClass.cast(artist)));
} else if (indexType == IndexType.ALBUM_ID3) {
Expand Down

0 comments on commit 2e2fc59

Please sign in to comment.