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 6f887cb563751608bc8b210b81477f8304aa48af..ada84f6abb67bbf8ad1b11245533e91b8e6734cd 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<OwnedClaim>?, val creationTime: OffsetDateTime = OffsetDateTime.now()) { @@ -29,8 +30,15 @@ class PolycentricCache { private val _cache = hashMapOf<PlatformID, CachedOwnedClaims>() private val _profileCache = hashMapOf<PublicKey, CachedPolycentricProfile>() - private val _profileUrlCache = FragmentedStorage.get<CachedPolycentricProfileStorage>("profileUrlCache") + private val _profileUrlCache: CachedPolycentricProfileStorage; private val _scope = CoroutineScope(Dispatchers.IO); + init { + Logger.i(TAG, "Initializing Polycentric cache"); + val time = measureTimeMillis { + _profileUrlCache = FragmentedStorage.get<CachedPolycentricProfileStorage>("profileUrlCache") + } + Logger.i(TAG, "Initialized Polycentric cache (${_profileUrlCache.map.size}, ${time}ms)"); + } private val _taskGetProfile = BatchedTaskHandler<PublicKey, CachedPolycentricProfile>(_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 9434d2f0b7bc35a8173706fd3382905d8c4e9e08..da9f96eaec5842253555b0921d1298cd2effd4d7 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 5c12771f8ff363347ee6cb5bcf23e1b10d02358d..be41f2179d83ad750110cbff87f4facc675fca8f 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<String> { - return getChannelUrlsWithUpdateResult(url, channelId, cacheOnly).second; + fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false, doCacheNull: Boolean = false): List<String> { + return getChannelUrlsWithUpdateResult(url, channelId, cacheOnly, doCacheNull).second; } - fun getChannelUrlsWithUpdateResult(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): Pair<Boolean, List<String>> { + fun getChannelUrlsWithUpdateResult(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false, doCacheNull: Boolean = false): Pair<Boolean, List<String>> { 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 a91f2104c57477d281183b4541f2b19bbf8b7a96..2e4c5854b54c2cb165d3b29134fb84750ab0e045 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 8b8fd55f39a5039ed15bee3b7e8e9a6ef5a6f538..fc5d17e19067efc0d28192b43de31f9bc499d288 160000 --- a/app/src/unstable/assets/sources/youtube +++ b/app/src/unstable/assets/sources/youtube @@ -1 +1 @@ -Subproject commit 8b8fd55f39a5039ed15bee3b7e8e9a6ef5a6f538 +Subproject commit fc5d17e19067efc0d28192b43de31f9bc499d288