mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 13:50:30 +05:30
refactor: improve bookmarks performance and reliability
This commit is contained in:
parent
a6e7576f34
commit
0ee013240c
@ -12,6 +12,9 @@ interface PlaylistBookmarkDao {
|
||||
@Query("SELECT * FROM playlistBookmark")
|
||||
suspend fun getAll(): List<PlaylistBookmark>
|
||||
|
||||
@Query("SELECT * FROM playlistBookmark WHERE playlistId = :playlistId LIMIT 1")
|
||||
suspend fun findById(playlistId: String): PlaylistBookmark?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insert(bookmark: PlaylistBookmark)
|
||||
|
||||
|
@ -29,6 +29,7 @@ import com.github.libretube.extensions.ceilHalf
|
||||
import com.github.libretube.extensions.dpToPx
|
||||
import com.github.libretube.helpers.NavBarHelper
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.helpers.ProxyHelper
|
||||
import com.github.libretube.ui.adapters.PlaylistBookmarkAdapter
|
||||
import com.github.libretube.ui.adapters.PlaylistsAdapter
|
||||
import com.github.libretube.ui.base.DynamicLayoutManagerFragment
|
||||
@ -140,7 +141,9 @@ class LibraryFragment : DynamicLayoutManagerFragment() {
|
||||
private fun initBookmarks() {
|
||||
lifecycleScope.launch {
|
||||
val bookmarks = withContext(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().getAll()
|
||||
DatabaseHolder.Database.playlistBookmarkDao().getAll().map {
|
||||
it.copy(thumbnailUrl = ProxyHelper.rewriteUrl(it.thumbnailUrl))
|
||||
}
|
||||
}
|
||||
|
||||
val binding = _binding ?: return@launch
|
||||
|
@ -290,8 +290,8 @@ class PlaylistFragment : DynamicLayoutManagerFragment() {
|
||||
if (!isBookmarked) return
|
||||
withContext(Dispatchers.IO) {
|
||||
// update the playlist thumbnail and title if bookmarked
|
||||
val playlistBookmark = DatabaseHolder.Database.playlistBookmarkDao().getAll()
|
||||
.firstOrNull { it.playlistId == playlistId } ?: return@withContext
|
||||
val playlistBookmark = DatabaseHolder.Database.playlistBookmarkDao().findById(playlistId)
|
||||
?: return@withContext
|
||||
if (playlistBookmark.thumbnailUrl != playlist.thumbnailUrl ||
|
||||
playlistBookmark.playlistName != playlist.name ||
|
||||
playlistBookmark.videos != playlist.videos
|
||||
|
Loading…
Reference in New Issue
Block a user