Merge pull request #6627 from Bnyro/master

refactor: improve performance when starting background shuffle mode
This commit is contained in:
Bnyro 2024-10-16 11:05:08 +02:00 committed by GitHub
commit e04d1ff974
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import com.github.libretube.db.obj.Download
import com.github.libretube.db.obj.DownloadChapter
import com.github.libretube.db.obj.DownloadItem
import com.github.libretube.db.obj.DownloadWithItems
import com.github.libretube.enums.FileType
@Dao
interface DownloadDao {
@ -22,6 +23,9 @@ interface DownloadDao {
@Query("SELECT * FROM download WHERE videoId = :videoId")
suspend fun findById(videoId: String): DownloadWithItems
@Query("SELECT videoId FROM downloadItem WHERE type = :fileType ORDER BY RANDOM() LIMIT 1")
suspend fun getRandomVideoIdByFileType(fileType: FileType): String?
@Query("SELECT * FROM downloaditem WHERE id = :id")
suspend fun findDownloadItemById(id: Int): DownloadItem?

View File

@ -42,8 +42,7 @@ class OfflinePlayerService : AbstractPlayerService() {
videoId = if (shuffle) {
runBlocking(Dispatchers.IO) {
Database.downloadDao().getAll().filterByTab(downloadTab)
.randomOrNull()?.download?.videoId
Database.downloadDao().getRandomVideoIdByFileType(FileType.AUDIO)
}
} else {
intent.getStringExtra(IntentData.videoId)