mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-04 23:30:52 +00:00
Reduce subscription calls, Improve subs sorting, Improve view sorting
This commit is contained in:
parent
aeaaace3a4
commit
4655d8369d
6 changed files with 19 additions and 12 deletions
|
@ -610,7 +610,7 @@ class VideoDetailView : ConstraintLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
val _trackingUpdateTimeLock = Object();
|
val _trackingUpdateTimeLock = Object();
|
||||||
val _trackingUpdateInterval = 3000;
|
val _trackingUpdateInterval = 2500;
|
||||||
var _trackingLastUpdateTime = System.currentTimeMillis();
|
var _trackingLastUpdateTime = System.currentTimeMillis();
|
||||||
var _trackingLastPosition: Long = 0;
|
var _trackingLastPosition: Long = 0;
|
||||||
var _trackingLastVideo: IPlatformVideoDetails? = null;
|
var _trackingLastVideo: IPlatformVideoDetails? = null;
|
||||||
|
|
|
@ -53,10 +53,12 @@ class Subscription {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldFetchVideos() = true;
|
fun shouldFetchVideos() = doFetchVideos &&
|
||||||
|
(lastVideo.getNowDiffDays() < 30 || lastVideoUpdate.getNowDiffDays() >= 1) &&
|
||||||
|
(lastVideo.getNowDiffDays() < 180 || lastVideoUpdate.getNowDiffDays() >= 3);
|
||||||
fun shouldFetchStreams() = doFetchStreams && lastLiveStream.getNowDiffDays() < 7;
|
fun shouldFetchStreams() = doFetchStreams && lastLiveStream.getNowDiffDays() < 7;
|
||||||
fun shouldFetchLiveStreams() = doFetchLive && lastLiveStream.getNowDiffDays() < 14;
|
fun shouldFetchLiveStreams() = doFetchLive && lastLiveStream.getNowDiffDays() < 14;
|
||||||
fun shouldFetchPosts() = doFetchPosts && lastPost.getNowDiffDays() < 2;
|
fun shouldFetchPosts() = doFetchPosts && lastPost.getNowDiffDays() < 5;
|
||||||
|
|
||||||
fun getClient() = StatePlatform.instance.getChannelClientOrNull(channel.url);
|
fun getClient() = StatePlatform.instance.getChannelClientOrNull(channel.url);
|
||||||
|
|
||||||
|
|
|
@ -85,21 +85,21 @@ class SmartSubscriptionAlgorithm(
|
||||||
ResultCapabilities.TYPE_STREAMS -> sub.lastLiveStream;
|
ResultCapabilities.TYPE_STREAMS -> sub.lastLiveStream;
|
||||||
ResultCapabilities.TYPE_LIVE -> sub.lastLiveStream;
|
ResultCapabilities.TYPE_LIVE -> sub.lastLiveStream;
|
||||||
ResultCapabilities.TYPE_POSTS -> sub.lastPost;
|
ResultCapabilities.TYPE_POSTS -> sub.lastPost;
|
||||||
else -> sub.lastVideo; //TODO: minimum of all
|
else -> sub.lastVideo; //TODO: minimum of all?
|
||||||
};
|
};
|
||||||
val lastUpdate = when(type) {
|
val lastUpdate = when(type) {
|
||||||
ResultCapabilities.TYPE_VIDEOS -> sub.lastVideoUpdate;
|
ResultCapabilities.TYPE_VIDEOS -> sub.lastVideoUpdate;
|
||||||
ResultCapabilities.TYPE_STREAMS -> sub.lastLiveStreamUpdate;
|
ResultCapabilities.TYPE_STREAMS -> sub.lastLiveStreamUpdate;
|
||||||
ResultCapabilities.TYPE_LIVE -> sub.lastLiveStreamUpdate;
|
ResultCapabilities.TYPE_LIVE -> sub.lastLiveStreamUpdate;
|
||||||
ResultCapabilities.TYPE_POSTS -> sub.lastPostUpdate;
|
ResultCapabilities.TYPE_POSTS -> sub.lastPostUpdate;
|
||||||
else -> sub.lastVideoUpdate; //TODO: minimum of all
|
else -> sub.lastVideoUpdate; //TODO: minimum of all?
|
||||||
};
|
};
|
||||||
val interval = when(type) {
|
val interval = when(type) {
|
||||||
ResultCapabilities.TYPE_VIDEOS -> sub.uploadInterval;
|
ResultCapabilities.TYPE_VIDEOS -> sub.uploadInterval;
|
||||||
ResultCapabilities.TYPE_STREAMS -> sub.uploadStreamInterval;
|
ResultCapabilities.TYPE_STREAMS -> sub.uploadStreamInterval;
|
||||||
ResultCapabilities.TYPE_LIVE -> sub.uploadStreamInterval;
|
ResultCapabilities.TYPE_LIVE -> sub.uploadStreamInterval;
|
||||||
ResultCapabilities.TYPE_POSTS -> sub.uploadPostInterval;
|
ResultCapabilities.TYPE_POSTS -> sub.uploadPostInterval;
|
||||||
else -> sub.uploadInterval; //TODO: minimum of all
|
else -> sub.uploadInterval; //TODO: minimum of all?
|
||||||
};
|
};
|
||||||
val lastItemDaysAgo = lastItem.getNowDiffHours();
|
val lastItemDaysAgo = lastItem.getNowDiffHours();
|
||||||
val lastUpdateHoursAgo = lastUpdate.getNowDiffHours();
|
val lastUpdateHoursAgo = lastUpdate.getNowDiffHours();
|
||||||
|
|
|
@ -54,7 +54,7 @@ abstract class SubscriptionsTaskFetchAlgorithm(
|
||||||
val clientTaskCount = clientTasks.value.filter { !it.fromCache }.size;
|
val clientTaskCount = clientTasks.value.filter { !it.fromCache }.size;
|
||||||
val clientCacheCount = clientTasks.value.size - clientTaskCount;
|
val clientCacheCount = clientTasks.value.size - clientTaskCount;
|
||||||
if(clientCacheCount > 0) {
|
if(clientCacheCount > 0) {
|
||||||
UIDialogs.toast("[${clientTasks.key.name}] only updating ${clientTaskCount} most urgent channels. (${clientCacheCount} cached)");
|
UIDialogs.toast("[${clientTasks.key.name}] only updating ${clientTaskCount} most urgent channels (rqs). (${clientCacheCount} cached)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,10 @@ class SubscriptionAdapter : RecyclerView.Adapter<SubscriptionViewHolder> {
|
||||||
|
|
||||||
private fun updateDataset() {
|
private fun updateDataset() {
|
||||||
_sortedDataset = when (sortBy) {
|
_sortedDataset = when (sortBy) {
|
||||||
0 -> StateSubscriptions.instance.getSubscriptions().sortedBy({ u -> u.channel.name })
|
0 -> StateSubscriptions.instance.getSubscriptions().sortedBy({ u -> u.channel.name.lowercase() })
|
||||||
1 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending({ u -> u.channel.name })
|
1 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending({ u -> u.channel.name.lowercase() })
|
||||||
2 -> StateSubscriptions.instance.getSubscriptions().sortedBy { it.playbackViews }
|
2 -> StateSubscriptions.instance.getSubscriptions().sortedBy { it.playbackViews * VIEW_PRIORITY + it.playbackSeconds }
|
||||||
3 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackViews }
|
3 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackViews * VIEW_PRIORITY + it.playbackSeconds }
|
||||||
4 -> StateSubscriptions.instance.getSubscriptions().sortedBy { it.playbackSeconds }
|
4 -> StateSubscriptions.instance.getSubscriptions().sortedBy { it.playbackSeconds }
|
||||||
5 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackSeconds }
|
5 -> StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackSeconds }
|
||||||
else -> throw IllegalStateException("Invalid sorting algorithm selected.");
|
else -> throw IllegalStateException("Invalid sorting algorithm selected.");
|
||||||
|
@ -65,4 +65,9 @@ class SubscriptionAdapter : RecyclerView.Adapter<SubscriptionViewHolder> {
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val VIEW_PRIORITY = 36000 * 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class SubscriptionBar : LinearLayout {
|
||||||
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) {
|
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) {
|
||||||
inflate(context, R.layout.view_subscription_bar, this);
|
inflate(context, R.layout.view_subscription_bar, this);
|
||||||
|
|
||||||
val subscriptions = StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackViews };
|
val subscriptions = StateSubscriptions.instance.getSubscriptions().sortedByDescending { it.playbackSeconds };
|
||||||
_adapterView = findViewById<RecyclerView>(R.id.recycler_creators).asAny(subscriptions, orientation = RecyclerView.HORIZONTAL) {
|
_adapterView = findViewById<RecyclerView>(R.id.recycler_creators).asAny(subscriptions, orientation = RecyclerView.HORIZONTAL) {
|
||||||
it.onClick.subscribe { c ->
|
it.onClick.subscribe { c ->
|
||||||
onClickChannel.emit(c.channel);
|
onClickChannel.emit(c.channel);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue