Fix issues when deleting the oldest read posts for users. No more app hangs.

This commit is contained in:
Docile-Alligator
2025-08-30 18:08:38 -04:00
parent 988c46fce2
commit 4829855179
5 changed files with 2 additions and 18 deletions

View File

@ -3112,7 +3112,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
mFragment.markPostAsRead(post);
}
}
}
@ -4140,7 +4139,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
mFragment.markPostAsRead(post);
}
}
}
@ -4383,7 +4381,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
mFragment.markPostAsRead(post);
}
}
}
@ -4580,7 +4577,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
mFragment.markPostAsRead(post);
}
}
}

View File

@ -67,10 +67,8 @@ import ml.docilealligator.infinityforreddit.post.PostPagingSource;
import ml.docilealligator.infinityforreddit.post.PostViewModel;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
import ml.docilealligator.infinityforreddit.readpost.ReadPostsList;
import ml.docilealligator.infinityforreddit.readpost.ReadPostsListInterface;
import ml.docilealligator.infinityforreddit.readpost.ReadPostsUtils;
import ml.docilealligator.infinityforreddit.thing.SortType;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
@ -1252,12 +1250,6 @@ public class PostFragment extends PostFragmentBase implements FragmentCommunicat
}
}
@Override
public void markPostAsRead(Post post) {
int readPostsLimit = ReadPostsUtils.GetReadPostsLimit(activity.accountName, mPostHistorySharedPreferences);
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, activity.accountName, post.getId(), readPostsLimit);
}
@Subscribe
public void onChangeDefaultPostLayoutEvent(ChangeDefaultPostLayoutEvent changeDefaultPostLayoutEvent) {
Bundle bundle = getArguments();

View File

@ -568,10 +568,6 @@ public abstract class PostFragmentBase extends Fragment {
}
}
public void markPostAsRead(Post post) {
// no-op
}
protected abstract boolean scrollPostsByCount(int count);
protected final void initializeSwipeActionDrawable() {

View File

@ -9,7 +9,7 @@ public class InsertReadPost {
String username, String postId, int readPostsLimit) {
executor.execute(() -> {
ReadPostDao readPostDao = redditDataRoomDatabase.readPostDao();
int limit = Math.max(readPostsLimit, 500);
int limit = Math.max(readPostsLimit, 100);
boolean isReadPostLimit = readPostsLimit != -1;
while (readPostDao.getReadPostsCount(username) > limit && isReadPostLimit) {
readPostDao.deleteOldestReadPosts(username);

View File

@ -26,7 +26,7 @@ public interface ReadPostDao {
@Query("SELECT COUNT(id) FROM read_posts WHERE username = :username")
int getReadPostsCount(String username);
@Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts ORDER BY time ASC LIMIT 100) AND username = :username")
@Query("DELETE FROM read_posts WHERE rowid IN (SELECT rowid FROM read_posts WHERE username = :username ORDER BY time ASC LIMIT 100)")
void deleteOldestReadPosts(String username);
@Query("DELETE FROM read_posts")