diff --git a/app/src/main/java/com/futo/platformplayer/states/StateApp.kt b/app/src/main/java/com/futo/platformplayer/states/StateApp.kt index 5b3521a9e316d06d2c70df68cb2b99bc26e237af..60552f23c79db0cee373cc4addb5dfbf2d4a361e 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateApp.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateApp.kt @@ -553,27 +553,6 @@ class StateApp { if(StateHistory.instance.shouldMigrateLegacyHistory()) StateHistory.instance.migrateLegacyHistory(); - - - if(false) { - /* - Logger.i(TAG, "TEST:--------(200)---------"); - testHistoryDB(200); - Logger.i(TAG, "TEST:--------(1000)---------"); - testHistoryDB(1000); - Logger.i(TAG, "TEST:--------(2000)---------"); - testHistoryDB(2000); - Logger.i(TAG, "TEST:--------(4000)---------"); - testHistoryDB(4000); - Logger.i(TAG, "TEST:--------(6000)---------"); - testHistoryDB(6000); - Logger.i(TAG, "TEST:--------(100000)---------"); - scope.launch(Dispatchers.Default) { - StateHistory.instance.testHistoryDB(100000); - } - */ - } - } fun mainAppStartedWithExternalFiles(context: Context) { diff --git a/app/src/main/java/com/futo/platformplayer/states/StateCache.kt b/app/src/main/java/com/futo/platformplayer/states/StateCache.kt index 10c6b94d44b12d219db517952a9b2826605c2476..9434d2f0b7bc35a8173706fd3382905d8c4e9e08 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateCache.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateCache.kt @@ -39,27 +39,16 @@ class StateCache { } fun getChannelCachePager(channelUrl: String): IPager<IPlatformContent> { - val result: IPager<IPlatformContent>; - val time = measureTimeMillis { - result = _subscriptionCache.queryPager(DBSubscriptionCache.Index::channelUrl, channelUrl, 20) { - it.obj; - } - } - return result; + return _subscriptionCache.queryPager(DBSubscriptionCache.Index::channelUrl, channelUrl, 20) { it.obj } } fun getAllChannelCachePager(channelUrls: List<String>): IPager<IPlatformContent> { - val result: IPager<IPlatformContent>; - val time = measureTimeMillis { - result = _subscriptionCache.queryInPager(DBSubscriptionCache.Index::channelUrl, channelUrls, 20) { - it.obj; - } - } - return result; + return _subscriptionCache.queryInPager(DBSubscriptionCache.Index::channelUrl, channelUrls, 20) { it.obj } } - fun getChannelCachePager(channelUrls: List<String>): IPager<IPlatformContent> { - val pagers = MultiChronoContentPager(channelUrls.map { _subscriptionCache.queryPager(DBSubscriptionCache.Index::channelUrl, it, 20) { + + fun getChannelCachePager(channelUrls: List<String>, pageSize: Int = 20): IPager<IPlatformContent> { + val pagers = MultiChronoContentPager(channelUrls.map { _subscriptionCache.queryPager(DBSubscriptionCache.Index::channelUrl, it, pageSize) { it.obj; - } }, false, 20); + } }, false, pageSize); return DedupContentPager(pagers, StatePlatform.instance.getEnabledClients().map { it.id }); } fun getSubscriptionCachePager(): DedupContentPager { @@ -67,7 +56,7 @@ class StateCache { val subs = StateSubscriptions.instance.getSubscriptions(); Logger.i(TAG, "Subscriptions CachePager polycentric urls"); val allUrls = subs.map { - val otherUrls = PolycentricCache.instance.getCachedProfile(it.channel.url)?.profile?.ownedClaims?.mapNotNull { c -> c.claim.resolveChannelUrl() } ?: listOf(); + val otherUrls = PolycentricCache.instance.getCachedProfile(it.channel.url)?.profile?.ownedClaims?.mapNotNull { c -> c.claim.resolveChannelUrl() } ?: listOf(); if(!otherUrls.contains(it.channel.url)) return@map listOf(listOf(it.channel.url), otherUrls).flatten(); else @@ -79,13 +68,6 @@ class StateCache { val timeCacheRetrieving = measureTimeMillis { pagers = listOf(getAllChannelCachePager(allUrls)); - - /*allUrls.parallelStream() - .map { - getChannelCachePager(it) - } - .asSequence() - .toList();*/ } Logger.i(TAG, "Subscriptions CachePager compiling (retrieved in ${timeCacheRetrieving}ms)"); diff --git a/app/src/main/java/com/futo/platformplayer/stores/db/ManagedDBContext.kt b/app/src/main/java/com/futo/platformplayer/stores/db/ManagedDBContext.kt deleted file mode 100644 index bcbf9cfab5de8e970e5e7db4b7bafbb9abc72bf3..0000000000000000000000000000000000000000 --- a/app/src/main/java/com/futo/platformplayer/stores/db/ManagedDBContext.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.futo.platformplayer.stores.db - -import androidx.room.Dao -import androidx.room.Delete -import androidx.room.Insert -import androidx.room.Query -import androidx.room.Update - -/* -@Dao -class ManagedDBContext<T, I: ManagedDBIndex<T>> { - - fun get(id: Int): I; - fun gets(vararg id: Int): List<I>; - fun getAll(): List<I>; - - @Insert - fun insert(index: I); - @Insert - fun insertAll(vararg indexes: I) - - @Update - fun update(index: I); - - @Delete - fun delete(index: I); -}*/ \ No newline at end of file diff --git a/app/src/main/java/com/futo/platformplayer/subscription/CachedSubscriptionAlgorithm.kt b/app/src/main/java/com/futo/platformplayer/subscription/CachedSubscriptionAlgorithm.kt index cba96ca58f581b50cdf9d018cd5cd4f9794102ac..3684790a320aca0b5f4dff5e463f769b2bd5dcde 100644 --- a/app/src/main/java/com/futo/platformplayer/subscription/CachedSubscriptionAlgorithm.kt +++ b/app/src/main/java/com/futo/platformplayer/subscription/CachedSubscriptionAlgorithm.kt @@ -1,42 +1,23 @@ package com.futo.platformplayer.subscription -import com.futo.platformplayer.api.media.models.contents.IPlatformContent import com.futo.platformplayer.api.media.platforms.js.JSClient import com.futo.platformplayer.api.media.structures.DedupContentPager -import com.futo.platformplayer.api.media.structures.IPager -import com.futo.platformplayer.api.media.structures.PlatformContentPager import com.futo.platformplayer.models.Subscription -import com.futo.platformplayer.polycentric.PolycentricCache -import com.futo.platformplayer.resolveChannelUrl import com.futo.platformplayer.states.StateCache import com.futo.platformplayer.states.StatePlatform -import com.futo.platformplayer.states.StateSubscriptions -import com.futo.platformplayer.toSafeFileName import kotlinx.coroutines.CoroutineScope import java.util.concurrent.ForkJoinPool -class CachedSubscriptionAlgorithm(pageSize: Int = 150, scope: CoroutineScope, allowFailure: Boolean = false, withCacheFallback: Boolean = true, threadPool: ForkJoinPool? = null) +class CachedSubscriptionAlgorithm(scope: CoroutineScope, allowFailure: Boolean = false, withCacheFallback: Boolean = true, threadPool: ForkJoinPool? = null, pageSize: Int = 50) : SubscriptionFetchAlgorithm(scope, allowFailure, withCacheFallback, threadPool) { private val _pageSize: Int = pageSize; override fun countRequests(subs: Map<Subscription, List<String>>): Map<JSClient, Int> { - return mapOf<JSClient, Int>(); + return mapOf(); } override fun getSubscriptions(subs: Map<Subscription, List<String>>): Result { - val validSubIds = subs.flatMap { it.value } .map { it.toSafeFileName() }.toHashSet(); - - /* - val validStores = StateCache.instance._channelContents - .filter { validSubIds.contains(it.key) } - .map { it.value };*/ - - /* - val items = validStores.flatMap { it.getItems() } - .sortedByDescending { it.datetime }; - */ - - return Result(DedupContentPager(StateCache.instance.getChannelCachePager(subs.flatMap { it.value }.distinct()), StatePlatform.instance.getEnabledClients().map { it.id }), listOf()); + return Result(DedupContentPager(StateCache.instance.getChannelCachePager(subs.flatMap { it.value }.distinct(), _pageSize), StatePlatform.instance.getEnabledClients().map { it.id }), listOf()); } } \ No newline at end of file diff --git a/app/src/main/java/com/futo/platformplayer/subscription/SubscriptionFetchAlgorithm.kt b/app/src/main/java/com/futo/platformplayer/subscription/SubscriptionFetchAlgorithm.kt index 4df2b6fd7839a17d76793986eea1d8c55dfcaf2a..4b5dd8b745ad71ba2a45688444d7847053cef8d7 100644 --- a/app/src/main/java/com/futo/platformplayer/subscription/SubscriptionFetchAlgorithm.kt +++ b/app/src/main/java/com/futo/platformplayer/subscription/SubscriptionFetchAlgorithm.kt @@ -38,7 +38,7 @@ abstract class SubscriptionFetchAlgorithm( fun getAlgorithm(algo: SubscriptionFetchAlgorithms, scope: CoroutineScope, allowFailure: Boolean = false, withCacheFallback: Boolean = false, pool: ForkJoinPool? = null): SubscriptionFetchAlgorithm { return when(algo) { - SubscriptionFetchAlgorithms.CACHE -> CachedSubscriptionAlgorithm(150, scope, allowFailure, withCacheFallback, pool); + SubscriptionFetchAlgorithms.CACHE -> CachedSubscriptionAlgorithm(scope, allowFailure, withCacheFallback, pool, 50); SubscriptionFetchAlgorithms.SIMPLE -> SimpleSubscriptionAlgorithm(scope, allowFailure, withCacheFallback, pool); SubscriptionFetchAlgorithms.SMART -> SmartSubscriptionAlgorithm(scope, allowFailure, withCacheFallback, pool); else -> throw IllegalStateException("Unknown algorithm ${algo}"); diff --git a/app/src/main/java/com/futo/platformplayer/views/adapters/HistoryListAdapter.kt b/app/src/main/java/com/futo/platformplayer/views/adapters/HistoryListAdapter.kt index ec8cde83ffedcb9668dd257e8edf780e8ba89cb3..33335adef90f507544f0065924d25c9f04b2cbd8 100644 --- a/app/src/main/java/com/futo/platformplayer/views/adapters/HistoryListAdapter.kt +++ b/app/src/main/java/com/futo/platformplayer/views/adapters/HistoryListAdapter.kt @@ -47,8 +47,7 @@ class HistoryListAdapter : RecyclerView.Adapter<HistoryListViewHolder> { fun updateFilteredVideos() { val videos = StateHistory.instance.getHistory(); - val pager = StateHistory.instance.getHistoryPager(); - //filtered val pager = StateHistory.instance.getHistorySearchPager("querrryyyyy"); + //filtered val pager = StateHistory.instance.getHistorySearchPager("querrryyyyy"); TODO: Implement pager if (_query.isBlank()) { _filteredVideos = videos.toMutableList();