From efc74a074ca99d251c2da4f0e2b653aa70986ad4 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Thu, 27 Jul 2023 08:22:34 +0200 Subject: [PATCH] No more infinity post loading! Loading should posts now stops if we could not load any new posts. This is particularly important, because previously the app made WAY TOO MANY requests. Signed-off-by: Balazs Toldi --- .../infinityforlemmy/post/PostPagingSource.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/post/PostPagingSource.java b/app/src/main/java/eu/toldi/infinityforlemmy/post/PostPagingSource.java index 1c0f36cb..ce19317a 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/post/PostPagingSource.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/post/PostPagingSource.java @@ -191,9 +191,19 @@ public class PostPagingSource extends ListenableFuturePagingSource(new Exception("Error parsing posts")); } else { + List trulyNewPosts = new ArrayList<>(); + for (Post post : newPosts) { + if (!postLinkedHashSet.contains(post)) { + trulyNewPosts.add(post); + } + } int currentPostsSize = postLinkedHashSet.size(); - postLinkedHashSet.addAll(newPosts); - int nextKey = (postLinkedHashSet.size()+1) / 25+1; + postLinkedHashSet.addAll(trulyNewPosts); + int nextKey = ++page; + if (trulyNewPosts.size() == 0) { + return new LoadResult.Page<>(new ArrayList<>(), null, null); + } + if (currentPostsSize == postLinkedHashSet.size()) { return new LoadResult.Page<>(new ArrayList<>(), null, nextKey); } else {