mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-06 16:19:28 +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) {
|
if (!StatePolycentric.instance.enabled || id.claimType <= 0) {
|
||||||
return CachedPolycentricProfile(null);
|
return CachedPolycentricProfile(null);
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,8 @@ class PolycentricCache {
|
||||||
Logger.v(TAG, "getProfileAsync (id: $id) != null (with retrieved valid claims)")
|
Logger.v(TAG, "getProfileAsync (id: $id) != null (with retrieved valid claims)")
|
||||||
return getProfileAsync(claims.ownedClaims.first().system).await()
|
return getProfileAsync(claims.ownedClaims.first().system).await()
|
||||||
} else {
|
} else {
|
||||||
|
if(url != null)
|
||||||
|
_profileUrlCache.setAndSave(url, PolycentricCache.CachedPolycentricProfile(null));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,17 +170,23 @@ class StatePolycentric {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): List<String> {
|
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) {
|
if (!enabled) {
|
||||||
return listOf(url);
|
return Pair(false, listOf(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
var polycentricProfile: PolycentricProfile? = null;
|
var polycentricProfile: PolycentricProfile? = null;
|
||||||
try {
|
try {
|
||||||
polycentricProfile = PolycentricCache.instance.getCachedProfile(url)?.profile;
|
val polycentricCached = PolycentricCache.instance.getCachedProfile(url, cacheOnly)
|
||||||
if (polycentricProfile == null && channelId != null) {
|
polycentricProfile = polycentricCached?.profile;
|
||||||
|
if (polycentricCached == null && channelId != null) {
|
||||||
Logger.i("StateSubscriptions", "Get polycentric profile not cached");
|
Logger.i("StateSubscriptions", "Get polycentric profile not cached");
|
||||||
if(!cacheOnly)
|
if(!cacheOnly) {
|
||||||
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId) }?.profile;
|
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId, url) }?.profile;
|
||||||
|
didUpdate = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger.i("StateSubscriptions", "Get polycentric profile cached");
|
Logger.i("StateSubscriptions", "Get polycentric profile cached");
|
||||||
}
|
}
|
||||||
|
@ -193,12 +199,12 @@ class StatePolycentric {
|
||||||
val urls = polycentricProfile.ownedClaims.groupBy { it.claim.claimType }
|
val urls = polycentricProfile.ownedClaims.groupBy { it.claim.claimType }
|
||||||
.mapNotNull { it.value.firstOrNull()?.claim?.resolveChannelUrl() }.toMutableList();
|
.mapNotNull { it.value.firstOrNull()?.claim?.resolveChannelUrl() }.toMutableList();
|
||||||
if(urls.any { it.equals(url, true) })
|
if(urls.any { it.equals(url, true) })
|
||||||
return urls;
|
return Pair(didUpdate, urls);
|
||||||
else
|
else
|
||||||
return listOf(url) + urls;
|
return Pair(didUpdate, listOf(url) + urls);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return listOf(url);
|
return Pair(didUpdate, listOf(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChannelContent(scope: CoroutineScope, profile: PolycentricProfile, isSubscriptionOptimized: Boolean = false, channelConcurrency: Int = -1): IPager<IPlatformContent>? {
|
fun getChannelContent(scope: CoroutineScope, profile: PolycentricProfile, isSubscriptionOptimized: Boolean = false, channelConcurrency: Int = -1): IPager<IPlatformContent>? {
|
||||||
|
|
|
@ -254,9 +254,17 @@ class StateSubscriptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
val usePolycentric = true;
|
val usePolycentric = true;
|
||||||
|
val lock = Object();
|
||||||
|
var polycentricBudget: Int = 10;
|
||||||
val subUrls = getSubscriptions().parallelStream().map {
|
val subUrls = getSubscriptions().parallelStream().map {
|
||||||
if(usePolycentric)
|
if(usePolycentric) {
|
||||||
Pair(it, StatePolycentric.instance.getChannelUrls(it.channel.url, it.channel.id));
|
val result = StatePolycentric.instance.getChannelUrlsWithUpdateResult(it.channel.url, it.channel.id, polycentricBudget <= 0);
|
||||||
|
if(result.first)
|
||||||
|
synchronized(lock) {
|
||||||
|
polycentricBudget--;
|
||||||
|
}
|
||||||
|
Pair(it, result.second);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Pair(it, listOf(it.channel.url));
|
Pair(it, listOf(it.channel.url));
|
||||||
}.asSequence()
|
}.asSequence()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue