mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
limit the home downloaded-songs preview in SQL
This commit is contained in:
@@ -709,9 +709,12 @@ interface LibraryDao {
|
||||
"LEFT JOIN albums ON albums.sourceId = songs.sourceId AND albums.id = songs.albumId " +
|
||||
"JOIN song_downloads d ON d.sourceId = songs.sourceId AND d.songId = songs.id " +
|
||||
"WHERE songs.sourceId = :sourceId AND d.status = 'Completed' " +
|
||||
"ORDER BY d.downloadedAt DESC, songs.title COLLATE NOCASE, songs.id",
|
||||
"ORDER BY d.downloadedAt DESC, songs.title COLLATE NOCASE, songs.id LIMIT :limit",
|
||||
)
|
||||
fun downloadedSongs(sourceId: Long): Flow<List<AlbumSongItem>>
|
||||
fun downloadedSongs(
|
||||
sourceId: Long,
|
||||
limit: Int,
|
||||
): Flow<List<AlbumSongItem>>
|
||||
|
||||
@Query(
|
||||
"SELECT songs.id FROM songs " +
|
||||
|
||||
@@ -88,7 +88,10 @@ class LibraryRepository(
|
||||
|
||||
fun starredSongs(sourceId: Long): Flow<PagingData<AlbumSongItem>> = pager(60) { db.libraryDao().starredSongs(sourceId) }
|
||||
|
||||
fun downloadedSongs(sourceId: Long): Flow<List<AlbumSongItem>> = db.libraryDao().downloadedSongs(sourceId)
|
||||
fun downloadedSongs(
|
||||
sourceId: Long,
|
||||
limit: Int,
|
||||
): Flow<List<AlbumSongItem>> = db.libraryDao().downloadedSongs(sourceId, limit)
|
||||
|
||||
fun downloadedSongsPage(sourceId: Long): Flow<PagingData<AlbumSongItem>> = pager(60) { db.libraryDao().homeDownloadedSongs(sourceId) }
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import kotlinx.coroutines.launch
|
||||
|
||||
const val HOME_ROW_LIMIT = 10
|
||||
const val HOME_STARRED_LIMIT = 5
|
||||
const val HOME_DOWNLOADED_LIMIT = 5
|
||||
|
||||
data class HomeFeed(
|
||||
val recentlyPlayedAlbums: List<Album> = emptyList(),
|
||||
@@ -81,9 +82,7 @@ class HomeViewModel(
|
||||
}.cachedIn(viewModelScope)
|
||||
|
||||
val downloadedSongs: Flow<List<AlbumSongItem>> =
|
||||
activeSource
|
||||
.flatMapLatest { libraryRepository.downloadedSongs(it) }
|
||||
.map { it.take(HOME_STARRED_LIMIT) }
|
||||
activeSource.flatMapLatest { libraryRepository.downloadedSongs(it, HOME_DOWNLOADED_LIMIT) }
|
||||
|
||||
val feed: StateFlow<HomeFeed> =
|
||||
libraryRepository.activeSourceId
|
||||
|
||||
Reference in New Issue
Block a user