diff --git a/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt b/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt index 6f887cb5..ada84f6a 100644 --- a/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt +++ b/app/src/main/java/com/futo/platformplayer/polycentric/PolycentricCache.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.* import kotlinx.serialization.Serializable import java.nio.ByteBuffer import java.time.OffsetDateTime +import kotlin.system.measureTimeMillis class PolycentricCache { data class CachedOwnedClaims(val ownedClaims: List?, val creationTime: OffsetDateTime = OffsetDateTime.now()) { @@ -29,8 +30,15 @@ class PolycentricCache { private val _cache = hashMapOf() private val _profileCache = hashMapOf() - private val _profileUrlCache = FragmentedStorage.get("profileUrlCache") + private val _profileUrlCache: CachedPolycentricProfileStorage; private val _scope = CoroutineScope(Dispatchers.IO); + init { + Logger.i(TAG, "Initializing Polycentric cache"); + val time = measureTimeMillis { + _profileUrlCache = FragmentedStorage.get("profileUrlCache") + } + Logger.i(TAG, "Initialized Polycentric cache (${_profileUrlCache.map.size}, ${time}ms)"); + } private val _taskGetProfile = BatchedTaskHandler(_scope, { system -> @@ -222,7 +230,7 @@ class PolycentricCache { } } - suspend fun getProfileAsync(id: PlatformID, url: String? = null): CachedPolycentricProfile? { + suspend fun getProfileAsync(id: PlatformID, urlNullCache: String? = null): CachedPolycentricProfile? { if (!StatePolycentric.instance.enabled || id.claimType <= 0) { return CachedPolycentricProfile(null); } @@ -243,8 +251,8 @@ class PolycentricCache { Logger.v(TAG, "getProfileAsync (id: $id) != null (with retrieved valid claims)") return getProfileAsync(claims.ownedClaims.first().system).await() } else { - if(url != null) - _profileUrlCache.setAndSave(url, PolycentricCache.CachedPolycentricProfile(null)); + if(urlNullCache != null) + _profileUrlCache.setAndSave(urlNullCache, PolycentricCache.CachedPolycentricProfile(null)); return null; } } 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 9434d2f0..da9f96ea 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateCache.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateCache.kt @@ -99,7 +99,7 @@ class StateCache { if(existing != null && doUpdate) { _subscriptionCache.update(existing.id!!, serialized); - return true; + return false; } else if(existing == null) { _subscriptionCache.insert(serialized); diff --git a/app/src/main/java/com/futo/platformplayer/states/StatePolycentric.kt b/app/src/main/java/com/futo/platformplayer/states/StatePolycentric.kt index 5c12771f..be41f217 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StatePolycentric.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StatePolycentric.kt @@ -169,10 +169,10 @@ class StatePolycentric { } } - fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): List { - return getChannelUrlsWithUpdateResult(url, channelId, cacheOnly).second; + fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false, doCacheNull: Boolean = false): List { + return getChannelUrlsWithUpdateResult(url, channelId, cacheOnly, doCacheNull).second; } - fun getChannelUrlsWithUpdateResult(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): Pair> { + fun getChannelUrlsWithUpdateResult(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false, doCacheNull: Boolean = false): Pair> { var didUpdate = false; if (!enabled) { return Pair(false, listOf(url)); @@ -184,7 +184,7 @@ class StatePolycentric { if (polycentricCached == null && channelId != null) { Logger.i("StateSubscriptions", "Get polycentric profile not cached"); if(!cacheOnly) { - polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId, url) }?.profile; + polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId, if(doCacheNull) url else null) }?.profile; didUpdate = true; } } else { diff --git a/app/src/main/java/com/futo/platformplayer/states/StateSubscriptions.kt b/app/src/main/java/com/futo/platformplayer/states/StateSubscriptions.kt index a91f2104..2e4c5854 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateSubscriptions.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateSubscriptions.kt @@ -258,7 +258,7 @@ class StateSubscriptions { var polycentricBudget: Int = 10; val subUrls = getSubscriptions().parallelStream().map { if(usePolycentric) { - val result = StatePolycentric.instance.getChannelUrlsWithUpdateResult(it.channel.url, it.channel.id, polycentricBudget <= 0); + val result = StatePolycentric.instance.getChannelUrlsWithUpdateResult(it.channel.url, it.channel.id, polycentricBudget <= 0, true); if(result.first) { synchronized(lock) { polycentricBudget--; diff --git a/app/src/unstable/assets/sources/youtube b/app/src/unstable/assets/sources/youtube index 8b8fd55f..fc5d17e1 160000 --- a/app/src/unstable/assets/sources/youtube +++ b/app/src/unstable/assets/sources/youtube @@ -1 +1 @@ -Subproject commit 8b8fd55f39a5039ed15bee3b7e8e9a6ef5a6f538 +Subproject commit fc5d17e19067efc0d28192b43de31f9bc499d288