mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #6627 from Bnyro/master
refactor: improve performance when starting background shuffle mode
This commit is contained in:
commit
e04d1ff974
@ -11,6 +11,7 @@ import com.github.libretube.db.obj.Download
|
|||||||
import com.github.libretube.db.obj.DownloadChapter
|
import com.github.libretube.db.obj.DownloadChapter
|
||||||
import com.github.libretube.db.obj.DownloadItem
|
import com.github.libretube.db.obj.DownloadItem
|
||||||
import com.github.libretube.db.obj.DownloadWithItems
|
import com.github.libretube.db.obj.DownloadWithItems
|
||||||
|
import com.github.libretube.enums.FileType
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface DownloadDao {
|
interface DownloadDao {
|
||||||
@ -22,6 +23,9 @@ interface DownloadDao {
|
|||||||
@Query("SELECT * FROM download WHERE videoId = :videoId")
|
@Query("SELECT * FROM download WHERE videoId = :videoId")
|
||||||
suspend fun findById(videoId: String): DownloadWithItems
|
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")
|
@Query("SELECT * FROM downloaditem WHERE id = :id")
|
||||||
suspend fun findDownloadItemById(id: Int): DownloadItem?
|
suspend fun findDownloadItemById(id: Int): DownloadItem?
|
||||||
|
|
||||||
|
@ -42,8 +42,7 @@ class OfflinePlayerService : AbstractPlayerService() {
|
|||||||
|
|
||||||
videoId = if (shuffle) {
|
videoId = if (shuffle) {
|
||||||
runBlocking(Dispatchers.IO) {
|
runBlocking(Dispatchers.IO) {
|
||||||
Database.downloadDao().getAll().filterByTab(downloadTab)
|
Database.downloadDao().getRandomVideoIdByFileType(FileType.AUDIO)
|
||||||
.randomOrNull()?.download?.videoId
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
intent.getStringExtra(IntentData.videoId)
|
intent.getStringExtra(IntentData.videoId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user