music: use sets for library information
Use a Set when storing all song, album, artist, and genre information. These all have no consistent ordering due to parallelization, and should be communicated as such.
This commit is contained in:
parent
5b44c31689
commit
d22de34fd3
4 changed files with 16 additions and 16 deletions
|
@ -203,7 +203,7 @@ class DeviceLibraryFactoryImpl @Inject constructor(private val musicSettings: Mu
|
||||||
|
|
||||||
// Now that all songs are processed, also process albums and group them into their
|
// Now that all songs are processed, also process albums and group them into their
|
||||||
// respective artists.
|
// respective artists.
|
||||||
val albums = albumGrouping.values.map { AlbumImpl(it, musicSettings) }
|
val albums = albumGrouping.values.mapTo(mutableSetOf()) { AlbumImpl(it, musicSettings) }
|
||||||
for (album in albums) {
|
for (album in albums) {
|
||||||
for (rawArtist in album.rawArtists) {
|
for (rawArtist in album.rawArtists) {
|
||||||
val key = RawArtist.Key(rawArtist)
|
val key = RawArtist.Key(rawArtist)
|
||||||
|
@ -236,18 +236,18 @@ class DeviceLibraryFactoryImpl @Inject constructor(private val musicSettings: Mu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Artists and genres do not need to be grouped and can be processed immediately.
|
// Artists and genres do not need to be grouped and can be processed immediately.
|
||||||
val artists = artistGrouping.values.map { ArtistImpl(it, musicSettings) }
|
val artists = artistGrouping.values.mapTo(mutableSetOf()) { ArtistImpl(it, musicSettings) }
|
||||||
val genres = genreGrouping.values.map { GenreImpl(it, musicSettings) }
|
val genres = genreGrouping.values.mapTo(mutableSetOf()) { GenreImpl(it, musicSettings) }
|
||||||
|
|
||||||
return DeviceLibraryImpl(songGrouping.values, albums, artists, genres)
|
return DeviceLibraryImpl(songGrouping.values.toSet(), albums, artists, genres)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeviceLibraryImpl(
|
class DeviceLibraryImpl(
|
||||||
override val songs: Collection<SongImpl>,
|
override val songs: Set<SongImpl>,
|
||||||
override val albums: Collection<AlbumImpl>,
|
override val albums: Set<AlbumImpl>,
|
||||||
override val artists: Collection<ArtistImpl>,
|
override val artists: Set<ArtistImpl>,
|
||||||
override val genres: Collection<GenreImpl>
|
override val genres: Set<GenreImpl>
|
||||||
) : DeviceLibrary {
|
) : DeviceLibrary {
|
||||||
// Use a mapping to make finding information based on it's UID much faster.
|
// Use a mapping to make finding information based on it's UID much faster.
|
||||||
private val songUidMap = buildMap { songs.forEach { put(it.uid, it.finalize()) } }
|
private val songUidMap = buildMap { songs.forEach { put(it.uid, it.finalize()) } }
|
||||||
|
|
|
@ -298,7 +298,7 @@ class AlbumImpl(
|
||||||
dates = if (min != null && max != null) Date.Range(min, max) else null
|
dates = if (min != null && max != null) Date.Range(min, max) else null
|
||||||
durationMs = totalDuration
|
durationMs = totalDuration
|
||||||
dateAdded = earliestDateAdded
|
dateAdded = earliestDateAdded
|
||||||
songs = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING).songs(grouping.music)
|
songs = Sort(Sort.Mode.ByTrack, Sort.Direction.ASCENDING).songs(grouping.music)
|
||||||
|
|
||||||
hashCode = 31 * hashCode + rawAlbum.hashCode()
|
hashCode = 31 * hashCode + rawAlbum.hashCode()
|
||||||
hashCode = 31 * hashCode + songs.hashCode()
|
hashCode = 31 * hashCode + songs.hashCode()
|
||||||
|
@ -394,7 +394,7 @@ class ArtistImpl(grouping: Grouping<RawArtist, Music>, musicSettings: MusicSetti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
songs = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING).songs(distinctSongs)
|
songs = Sort(Sort.Mode.ByDate, Sort.Direction.ASCENDING).songs(distinctSongs)
|
||||||
albums = Sort(Sort.Mode.ByDate, Sort.Direction.DESCENDING).albums(albumMap.keys)
|
albums = Sort(Sort.Mode.ByDate, Sort.Direction.DESCENDING).albums(albumMap.keys)
|
||||||
explicitAlbums = albums.filter { unlikelyToBeNull(albumMap[it]) }
|
explicitAlbums = albums.filter { unlikelyToBeNull(albumMap[it]) }
|
||||||
implicitAlbums = albums.filterNot { unlikelyToBeNull(albumMap[it]) }
|
implicitAlbums = albums.filterNot { unlikelyToBeNull(albumMap[it]) }
|
||||||
|
|
|
@ -121,7 +121,7 @@ data class RawAlbum(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows [RawAlbum]s to be compared by "fundamental" information that is unlikely to change on
|
* Allows [RawAlbum]s to be compared by "fundamental" information that is unlikely to change on
|
||||||
* an item-by-item basis.
|
* an item-by-item
|
||||||
*/
|
*/
|
||||||
data class Key(private val inner: RawAlbum) {
|
data class Key(private val inner: RawAlbum) {
|
||||||
// Albums are grouped as follows:
|
// Albums are grouped as follows:
|
||||||
|
@ -169,7 +169,7 @@ data class RawArtist(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows [RawArtist]s to be compared by "fundamental" information that is unlikely to change on
|
* Allows [RawArtist]s to be compared by "fundamental" information that is unlikely to change on
|
||||||
* an item-by-item basis.
|
* an item-by-item
|
||||||
*/
|
*/
|
||||||
data class Key(private val inner: RawArtist) {
|
data class Key(private val inner: RawArtist) {
|
||||||
// Artists are grouped as follows:
|
// Artists are grouped as follows:
|
||||||
|
@ -216,7 +216,7 @@ data class RawGenre(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows [RawGenre]s to be compared by "fundamental" information that is unlikely to change on
|
* Allows [RawGenre]s to be compared by "fundamental" information that is unlikely to change on
|
||||||
* an item-by-item basis.
|
* an item-by-item
|
||||||
*/
|
*/
|
||||||
data class Key(private val inner: RawGenre) {
|
data class Key(private val inner: RawGenre) {
|
||||||
// Cache the hashCode for HashMap efficiency.
|
// Cache the hashCode for HashMap efficiency.
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.oxycblt.auxio.util.logE
|
||||||
*/
|
*/
|
||||||
interface UserLibrary {
|
interface UserLibrary {
|
||||||
/** The current user-defined playlists. */
|
/** The current user-defined playlists. */
|
||||||
val playlists: List<Playlist>
|
val playlists: Collection<Playlist>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a [Playlist] instance corresponding to the given [Music.UID].
|
* Find a [Playlist] instance corresponding to the given [Music.UID].
|
||||||
|
@ -173,8 +173,8 @@ private class UserLibraryImpl(
|
||||||
override fun equals(other: Any?) = other is UserLibraryImpl && other.playlistMap == playlistMap
|
override fun equals(other: Any?) = other is UserLibraryImpl && other.playlistMap == playlistMap
|
||||||
override fun toString() = "UserLibrary(playlists=${playlists.size})"
|
override fun toString() = "UserLibrary(playlists=${playlists.size})"
|
||||||
|
|
||||||
override val playlists: List<Playlist>
|
override val playlists: Collection<Playlist>
|
||||||
get() = playlistMap.values.toList()
|
get() = playlistMap.values.toSet()
|
||||||
|
|
||||||
override fun findPlaylist(uid: Music.UID) = playlistMap[uid]
|
override fun findPlaylist(uid: Music.UID) = playlistMap[uid]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue