Primary claim support, fix sub for clients without type

This commit is contained in:
Kelvin 2023-11-03 18:17:04 +01:00
commit 7eef6eece2
10 changed files with 17 additions and 12 deletions

View file

@ -584,7 +584,7 @@ open class JSClient : IPlatformClient {
if(it.containsKey(claimType)) { if(it.containsKey(claimType)) {
val templates = it[claimType]; val templates = it[claimType];
if(templates != null) if(templates != null)
for(value in values.keys.sortedBy { it }) { for(value in values.keys.sortedBy { if(it == config.primaryClaimFieldType) Int.MIN_VALUE else it }) {
if(templates.containsKey(value)) { if(templates.containsKey(value)) {
return templates[value]!!.replace("{{CLAIMVALUE}}", values[value]!!); return templates[value]!!.replace("{{CLAIMVALUE}}", values[value]!!);
} }

View file

@ -45,7 +45,8 @@ class SourcePluginConfig(
var subscriptionRateLimit: Int? = null, var subscriptionRateLimit: Int? = null,
var enableInSearch: Boolean = true, var enableInSearch: Boolean = true,
var enableInHome: Boolean = true, var enableInHome: Boolean = true,
var supportedClaimTypes: List<Int> = listOf() var supportedClaimTypes: List<Int> = listOf(),
var primaryClaimFieldType: Int? = null
) : IV8PluginConfig { ) : IV8PluginConfig {
val absoluteIconUrl: String? get() = resolveAbsoluteUrl(iconUrl, sourceUrl); val absoluteIconUrl: String? get() = resolveAbsoluteUrl(iconUrl, sourceUrl);

View file

@ -178,7 +178,7 @@ class SubscriptionsFeedFragment : MainFragment() {
val subRequestCounts = StateSubscriptions.instance.getSubscriptionRequestCount(); val subRequestCounts = StateSubscriptions.instance.getSubscriptionRequestCount();
val reqCountStr = subRequestCounts.map { " ${it.key.config.name}: ${it.value}/${it.key.getSubscriptionRateLimit()}" }.joinToString("\n"); val reqCountStr = subRequestCounts.map { " ${it.key.config.name}: ${it.value}/${it.key.getSubscriptionRateLimit()}" }.joinToString("\n");
val rateLimitPlugins = subRequestCounts.filter { clientCount -> clientCount.key.getSubscriptionRateLimit()?.let { rateLimit -> clientCount.value > rateLimit } == true } val rateLimitPlugins = subRequestCounts.filter { clientCount -> clientCount.key.getSubscriptionRateLimit()?.let { rateLimit -> clientCount.value > rateLimit } == true }
Logger.w(TAG, "Refreshing subscriptions with requests:\n" + reqCountStr); Logger.w(TAG, "Trying to refreshing subscriptions with requests:\n" + reqCountStr);
if(rateLimitPlugins.any()) if(rateLimitPlugins.any())
throw RateLimitException(rateLimitPlugins.map { it.key.id }); throw RateLimitException(rateLimitPlugins.map { it.key.id });
} }

View file

@ -407,8 +407,9 @@ class StatePlatform {
return@async searchResult; return@async searchResult;
} catch(ex: Throwable) { } catch(ex: Throwable) {
Logger.e(TAG, "getHomeRefresh", ex); Logger.e(TAG, "getHomeRefresh", ex);
throw ex; //throw ex;
//return@async null; //return@async null;
return@async PlaceholderPager(10, { PlatformContentPlaceholder(it.id, ex) });
} }
}); });
}.toList(); }.toList();

View file

@ -144,14 +144,15 @@ class StatePolycentric {
return DedupContentPager(pager, StatePlatform.instance.getEnabledClients().map { it.id }); return DedupContentPager(pager, StatePlatform.instance.getEnabledClients().map { it.id });
} }
fun getChannelUrls(url: String, channelId: PlatformID? = null): List<String> { fun getChannelUrls(url: String, channelId: PlatformID? = null, cacheOnly: Boolean = false): List<String> {
var polycentricProfile: PolycentricProfile? = null; var polycentricProfile: PolycentricProfile? = null;
try { try {
polycentricProfile = PolycentricCache.instance.getCachedProfile(url)?.profile; polycentricProfile = PolycentricCache.instance.getCachedProfile(url)?.profile;
if (polycentricProfile == null && channelId != null) { if (polycentricProfile == null && channelId != null) {
Logger.i("StateSubscriptions", "Get polycentric profile not cached"); Logger.i("StateSubscriptions", "Get polycentric profile not cached");
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId) }?.profile; if(!cacheOnly)
polycentricProfile = runBlocking { PolycentricCache.instance.getProfileAsync(channelId) }?.profile;
} else { } else {
Logger.i("StateSubscriptions", "Get polycentric profile cached"); Logger.i("StateSubscriptions", "Get polycentric profile cached");
} }

View file

@ -241,7 +241,7 @@ class StateSubscriptions {
fun getSubscriptionRequestCount(): Map<JSClient, Int> { fun getSubscriptionRequestCount(): Map<JSClient, Int> {
return SubscriptionFetchAlgorithm.getAlgorithm(_algorithmSubscriptions, StateApp.instance.scope) return SubscriptionFetchAlgorithm.getAlgorithm(_algorithmSubscriptions, StateApp.instance.scope)
.countRequests(getSubscriptions()); .countRequests(getSubscriptions().associateWith { StatePolycentric.instance.getChannelUrls(it.channel.url, it.channel.id, true) });
} }
fun getSubscriptionsFeedWithExceptions(allowFailure: Boolean = false, withCacheFallback: Boolean = false, cacheScope: CoroutineScope, onProgress: ((Int, Int)->Unit)? = null, onNewCacheHit: ((Subscription, IPlatformContent)->Unit)? = null): Pair<IPager<IPlatformContent>, List<Throwable>> { fun getSubscriptionsFeedWithExceptions(allowFailure: Boolean = false, withCacheFallback: Boolean = false, cacheScope: CoroutineScope, onProgress: ((Int, Int)->Unit)? = null, onNewCacheHit: ((Subscription, IPlatformContent)->Unit)? = null): Pair<IPager<IPlatformContent>, List<Throwable>> {

View file

@ -33,7 +33,7 @@ class SmartSubscriptionAlgorithm(
val client = it.value!! as JSClient; val client = it.value!! as JSClient;
val capabilities = client.getChannelCapabilities(); val capabilities = client.getChannelCapabilities();
if(capabilities.hasType(ResultCapabilities.TYPE_MIXED)) if(capabilities.hasType(ResultCapabilities.TYPE_MIXED) || capabilities.types.isEmpty())
return@flatMap listOf(SubscriptionTask(client, sub, it.key, ResultCapabilities.TYPE_MIXED)); return@flatMap listOf(SubscriptionTask(client, sub, it.key, ResultCapabilities.TYPE_MIXED));
else { else {
val types = listOf( val types = listOf(

View file

@ -16,6 +16,7 @@ import com.futo.platformplayer.engine.exceptions.ScriptCaptchaRequiredException
import com.futo.platformplayer.engine.exceptions.ScriptCriticalException import com.futo.platformplayer.engine.exceptions.ScriptCriticalException
import com.futo.platformplayer.exceptions.ChannelException import com.futo.platformplayer.exceptions.ChannelException
import com.futo.platformplayer.findNonRuntimeException import com.futo.platformplayer.findNonRuntimeException
import com.futo.platformplayer.fragment.mainactivity.main.SubscriptionsFeedFragment
import com.futo.platformplayer.logging.Logger import com.futo.platformplayer.logging.Logger
import com.futo.platformplayer.models.Subscription import com.futo.platformplayer.models.Subscription
import com.futo.platformplayer.states.StatePlatform import com.futo.platformplayer.states.StatePlatform
@ -46,9 +47,10 @@ abstract class SubscriptionsTaskFetchAlgorithm(
val tasksGrouped = tasks.groupBy { it.client } val tasksGrouped = tasks.groupBy { it.client }
val taskCount = tasks.filter { !it.fromCache }.size; val taskCount = tasks.filter { !it.fromCache }.size;
val cacheCount = tasks.size - taskCount; val cacheCount = tasks.size - taskCount;
Logger.i(TAG, "Starting Subscriptions Fetch:\n" + Logger.i(TAG, "Starting Subscriptions Fetch:\n" +
" Tasks: ${taskCount}\n" + tasksGrouped.map { " ${it.key.name}: ${it.value.count { !it.fromCache }}, Cached(${it.value.count { it.fromCache } })" }.joinToString("\n"));
" Cached: ${cacheCount}");
try { try {
for(clientTasks in tasksGrouped) { for(clientTasks in tasksGrouped) {
val clientTaskCount = clientTasks.value.filter { !it.fromCache }.size; val clientTaskCount = clientTasks.value.filter { !it.fromCache }.size;

@ -1 +1 @@
Subproject commit 948835fa682b6e536bf05f66b426144ef5b47e69 Subproject commit b6db44bf3ba2825fca9b86c3867204467cfb334f

@ -1 +1 @@
Subproject commit ae803c9295cf3d53aa49ddc2799d0f86aecc06a6 Subproject commit fca0ba3d5ae20baf0586cfea1f716ef4bc00c2f7