Skip to content
Snippets Groups Projects
Commit b0a35bcf authored by Kelvin's avatar Kelvin
Browse files

No notification on known item, Polycentric logging, refs

parent 0e748232
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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 {
......
......@@ -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--;
......
Subproject commit 8b8fd55f39a5039ed15bee3b7e8e9a6ef5a6f538
Subproject commit fc5d17e19067efc0d28192b43de31f9bc499d288
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment