Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wordpress.android.ui.reader.actions;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Pair;

Expand Down Expand Up @@ -32,8 +34,15 @@

import java.net.HttpURLConnection;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ReaderBlogActions {
// Serial worker for Reader DB writes triggered from Volley response callbacks. Using a single
// shared executor avoids spawning a thread per response and lets SQLite writes queue naturally.
private static final ExecutorService DB_EXECUTOR = Executors.newSingleThreadExecutor();
private static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());

public static class BlockedBlogResult {
public long blogId;
public long feedId;
Expand Down Expand Up @@ -456,12 +465,14 @@ private static void handleUpdateBlogInfoResponse(JSONObject jsonObject, UpdateBl
return;
}

ReaderBlog blogInfo = ReaderBlog.fromJson(jsonObject);
ReaderBlogTable.addOrUpdateBlog(blogInfo);

if (infoListener != null) {
infoListener.onResult(blogInfo);
}
final ReaderBlog blogInfo = ReaderBlog.fromJson(jsonObject);
// Move the INSERT OR REPLACE off the main thread; callers expect onResult on main.
DB_EXECUTOR.execute(() -> {
ReaderBlogTable.addOrUpdateBlog(blogInfo);
if (infoListener != null) {
MAIN_HANDLER.post(() -> infoListener.onResult(blogInfo));
}
});
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ReaderPostRepository @Inject constructor(
if (updateAction == ReaderPostServiceStarter.UpdateAction.REQUEST_NEWER ||
updateAction == ReaderPostServiceStarter.UpdateAction.REQUEST_REFRESH
) {
ReaderTagTable.setTagLastUpdated(tag)
applicationScope.launch(ioDispatcher) { ReaderTagTable.setTagLastUpdated(tag) }
}
handleUpdatePostsResponse(tag, jsonObject, updateAction, resultListener)
}
Expand Down Expand Up @@ -352,7 +352,7 @@ class ReaderPostRepository @Inject constructor(
if (updateAction == ReaderPostServiceStarter.UpdateAction.REQUEST_NEWER ||
updateAction == ReaderPostServiceStarter.UpdateAction.REQUEST_REFRESH
) {
ReaderTagTable.setTagLastUpdated(tag)
applicationScope.launch(ioDispatcher) { ReaderTagTable.setTagLastUpdated(tag) }
}
handleUpdatePostsResponse(tag, jsonObject, updateAction, resultListener)
}
Expand Down
Loading