mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Merge branch 'master' of gitlab.futo.org:videostreaming/grayjay
This commit is contained in:
commit
8b20b4909f
3 changed files with 28 additions and 12 deletions
|
@ -222,7 +222,7 @@ class PolycentricCache {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getProfileAsync(id: PlatformID): CachedPolycentricProfile? {
|
||||
suspend fun getProfileAsync(id: PlatformID, url: String? = null): CachedPolycentricProfile? {
|
||||
if (!StatePolycentric.instance.enabled || id.claimType <= 0) {
|
||||
return CachedPolycentricProfile(null);
|
||||
}
|
||||
|
@ -243,6 +243,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));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,17 +170,23 @@ class StatePolycentric {
|
|||
}
|
||||
|
||||
fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): List<String> {
|
||||
return getChannelUrlsWithUpdateResult(url, channelId, cacheOnly).second;
|
||||
}
|
||||
fun getChannelUrlsWithUpdateResult(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): Pair<Boolean, List<String>> {
|
||||
var didUpdate = false;
|
||||
if (!enabled) {
|
||||
return listOf(url);
|
||||
return Pair(false, listOf(url));
|
||||
}
|
||||
|
||||
var polycentricProfile: PolycentricProfile? = null;
|
||||
try {
|
||||
polycentricProfile = PolycentricCache.instance.getCachedProfile(url)?.profile;
|
||||
if (polycentricProfile == null && channelId != null) {
|
||||
val polycentricCached = PolycentricCache.instance.getCachedProfile(url, cacheOnly)
|
||||
polycentricProfile = polycentricCached?.profile;
|
||||
if (polycentricCached == null && channelId != null) {
|
||||
Logger.i("StateSubscriptions", "Get polycentric profile not cached");
|
||||
if(!cacheOnly)
|
||||
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId) }?.profile;
|
||||
if(!cacheOnly) {
|
||||
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId, url) }?.profile;
|
||||
didUpdate = true;
|
||||
}
|
||||
} else {
|
||||
Logger.i("StateSubscriptions", "Get polycentric profile cached");
|
||||
}
|
||||
|
@ -193,12 +199,12 @@ class StatePolycentric {
|
|||
val urls = polycentricProfile.ownedClaims.groupBy { it.claim.claimType }
|
||||
.mapNotNull { it.value.firstOrNull()?.claim?.resolveChannelUrl() }.toMutableList();
|
||||
if(urls.any { it.equals(url, true) })
|
||||
return urls;
|
||||
return Pair(didUpdate, urls);
|
||||
else
|
||||
return listOf(url) + urls;
|
||||
return Pair(didUpdate, listOf(url) + urls);
|
||||
}
|
||||
else
|
||||
return listOf(url);
|
||||
return Pair(didUpdate, listOf(url));
|
||||
}
|
||||
|
||||
fun getChannelContent(scope: CoroutineScope, profile: PolycentricProfile, isSubscriptionOptimized: Boolean = false, channelConcurrency: Int = -1): IPager<IPlatformContent>? {
|
||||
|
|
|
@ -254,9 +254,17 @@ class StateSubscriptions {
|
|||
}
|
||||
|
||||
val usePolycentric = true;
|
||||
val lock = Object();
|
||||
var polycentricBudget: Int = 10;
|
||||
val subUrls = getSubscriptions().parallelStream().map {
|
||||
if(usePolycentric)
|
||||
Pair(it, StatePolycentric.instance.getChannelUrls(it.channel.url, it.channel.id));
|
||||
if(usePolycentric) {
|
||||
val result = StatePolycentric.instance.getChannelUrlsWithUpdateResult(it.channel.url, it.channel.id, polycentricBudget <= 0);
|
||||
if(result.first)
|
||||
synchronized(lock) {
|
||||
polycentricBudget--;
|
||||
}
|
||||
Pair(it, result.second);
|
||||
}
|
||||
else
|
||||
Pair(it, listOf(it.channel.url));
|
||||
}.asSequence()
|
||||
|
|
Loading…
Add table
Reference in a new issue