mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
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 <balazs@toldi.eu>
This commit is contained in:
parent
3b5852d1e4
commit
efc74a074c
@ -191,9 +191,19 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
if (newPosts == null) {
|
||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||
} else {
|
||||
List<Post> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user