Upper limit on mark-read batch size auto-flushes.

This commit is contained in:
ojiikun 2013-05-10 21:06:41 +00:00
parent b12a83465e
commit 84be7ea490
2 changed files with 21 additions and 8 deletions

View file

@ -188,14 +188,11 @@ public abstract class Reading extends NbFragmentActivity implements OnPageChange
public abstract void triggerRefresh();
public abstract void triggerRefresh(int page);
@Override
protected void onPause() {
synchronized(this.storiesToMarkAsRead) {
FeedUtils.markStoriesAsRead(this.storiesToMarkAsRead, this);
this.storiesToMarkAsRead.clear();
}
super.onPause();
}
@Override
protected void onPause() {
flushStoriesMarkedRead();
super.onPause();
}
/**
* Log a story as having been read. The local DB and remote server will be updated
@ -207,6 +204,19 @@ public abstract class Reading extends NbFragmentActivity implements OnPageChange
synchronized (this.storiesToMarkAsRead) {
this.storiesToMarkAsRead.add(story);
}
// flush immediately if the batch reaches a sufficient size
if (this.storiesToMarkAsRead.size() >= AppConstants.MAX_MARK_READ_BATCH) {
flushStoriesMarkedRead();
}
}
private void flushStoriesMarkedRead() {
synchronized(this.storiesToMarkAsRead) {
if (this.storiesToMarkAsRead.size() > 0) {
FeedUtils.markStoriesAsRead(this.storiesToMarkAsRead, this);
this.storiesToMarkAsRead.clear();
}
}
}
@Override

View file

@ -19,4 +19,7 @@ public class AppConstants {
public static final String ROOT_FOLDER = "0000_TOP_LEVEL_";
public static final String LAST_APP_VERSION = "LAST_APP_VERSION";
// the max number of mark-as-read ops to batch up before flushing to the server
public static final int MAX_MARK_READ_BATCH = 5;
}