Skip to content

Commit

Permalink
⚡ limit PV search results to PvService.currentlyRenderableEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
CXwudi committed Jan 3, 2024
1 parent a390aef commit a04e505
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ enum class PvService {
Bandcamp;

fun isOnlineService() = this != File && this != LocalFile

companion object {
val currentlyRenderableEntries = listOf(
NicoNicoDouga,
Youtube,
SoundCloud,
Bilibili,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package mikufan.cx.songfinder.backend.db.repository

import mikufan.cx.songfinder.backend.db.entity.Pv
import mikufan.cx.songfinder.backend.db.entity.PvService
import org.springframework.stereotype.Repository

@Repository
interface PvRepository : VocaDbRepository<Pv, Long> {
fun findAllBySongIdIn(songIds: List<Long>): List<Pv>
fun findAllBySongIdInAndPvServiceIn(
songIds: List<Long>,
pvServices: List<PvService> = PvService.currentlyRenderableEntries
): List<Pv>
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SongSearchService(

// 3. search all PVs
val songIdToPv: Map<SongId, List<Pv>> = withContext(ioDispatcher) {
pvRepo.findAllBySongIdIn(songIds)
pvRepo.findAllBySongIdInAndPvServiceIn(songIds)
}
.groupBy { it.songId }
log.debug { "found $songIdToPv PVs" }
Expand Down Expand Up @@ -166,8 +166,7 @@ class SongSearchService(
songId: SongId,
songIdToPvs: Map<SongId, List<Pv>>
): List<PVInfo> = songIdToPvs[songId]?.let { pvs ->
pvs.filter { it.pvService.isOnlineService() }
.map { PVInfo(it.pvId, it.pvService, it.pvType, it.extendedMetadata) }
pvs.map { PVInfo(it.pvId, it.pvService, it.pvType, it.extendedMetadata) }
} ?: emptyList<PVInfo>().also {
log.warn { "No PV found for song $songId" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,16 @@ fun LazyGridItemScope.RealResultGridCell(
callbacks: ResultCellCallbacks,
modifier: Modifier = Modifier
) {
val filteredPvs: List<PVInfo> by produceState(listOf()) {
value = result.pvs.filter {
it.pvService in listOf(
PvService.Youtube,
PvService.NicoNicoDouga,
PvService.SoundCloud,
PvService.Bilibili
)
}
}
val pvs = result.pvs
MusicCardTemplate(
onCardClicked = { callbacks.onCardClicked(result) },
modifier.animateItemPlacement()
) {
LazilyFetchedThumbnail(
filteredPvs,
pvs,
provideThumbnailInfoCallback = callbacks.provideThumbnailInfo,
)
MusicInfo(result, filteredPvs)
MusicInfo(result, pvs)
}
}

Expand Down

0 comments on commit a04e505

Please sign in to comment.