mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-06 18:57:26 +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) {
|
if (newPosts == null) {
|
||||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||||
} else {
|
} else {
|
||||||
|
List<Post> trulyNewPosts = new ArrayList<>();
|
||||||
|
for (Post post : newPosts) {
|
||||||
|
if (!postLinkedHashSet.contains(post)) {
|
||||||
|
trulyNewPosts.add(post);
|
||||||
|
}
|
||||||
|
}
|
||||||
int currentPostsSize = postLinkedHashSet.size();
|
int currentPostsSize = postLinkedHashSet.size();
|
||||||
postLinkedHashSet.addAll(newPosts);
|
postLinkedHashSet.addAll(trulyNewPosts);
|
||||||
int nextKey = (postLinkedHashSet.size()+1) / 25+1;
|
int nextKey = ++page;
|
||||||
|
if (trulyNewPosts.size() == 0) {
|
||||||
|
return new LoadResult.Page<>(new ArrayList<>(), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentPostsSize == postLinkedHashSet.size()) {
|
if (currentPostsSize == postLinkedHashSet.size()) {
|
||||||
return new LoadResult.Page<>(new ArrayList<>(), null, nextKey);
|
return new LoadResult.Page<>(new ArrayList<>(), null, nextKey);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user