Reduce some UI lag from racing API requests.

This commit is contained in:
dosiecki 2015-11-29 15:24:13 -08:00
parent 3b1d0e989c
commit 72afc02b89
3 changed files with 32 additions and 14 deletions

View file

@ -366,9 +366,16 @@ public class NBSyncService extends Service {
impactFlags |= impact;
}
NbActivity.updateAllActivities(impactFlags);
if (PendingFeed == null) {
FollowupActions.clear();
}
// if there is a feed fetch loop running, don't clear, there will likely be races for
// stories that were just tapped as they were being re-fetched
synchronized (PENDING_FEED_MUTEX) {if (PendingFeed != null) return;}
// if there is a what-is-unread sync in progress, hold off on confirming actions,
// as this subservice can vend stale unread data
if (UnreadsService.isDoMetadata()) return;
FollowupActions.clear();
}
/**
@ -396,13 +403,6 @@ public class NBSyncService extends Service {
orphanFeedIds = new HashSet<String>();
try {
// a metadata sync invalidates pagination and feed status
ExhaustedFeeds.clear();
FeedPagesSeen.clear();
FeedStoriesSeen.clear();
UnreadsService.clear();
RecountCandidates.clear();
FeedFolderResponse feedResponse = apiManager.getFolderFeedMapping(true);
if (feedResponse == null) {
@ -417,6 +417,13 @@ public class NBSyncService extends Service {
return;
}
// a metadata sync invalidates pagination and feed status
ExhaustedFeeds.clear();
FeedPagesSeen.clear();
FeedStoriesSeen.clear();
UnreadsService.clear();
RecountCandidates.clear();
lastFFConnMillis = feedResponse.connTime;
lastFFReadMillis = feedResponse.readTime;
lastFFParseMillis = feedResponse.parseTime;
@ -596,7 +603,10 @@ public class NBSyncService extends Service {
while (totalStoriesSeen < PendingFeedTarget) {
if (stopSync()) return;
// this is a good heuristic for double-checking if we have left the story list
if (FlushRecounts) return;
// don't let the page loop block actions
if (dbHelper.getActions(false).getCount() > 0) return;
if (!fs.equals(PendingFeed)) {
// the active view has changed
if (fs == null) finished = true;
@ -629,6 +639,9 @@ public class NBSyncService extends Service {
finished = true;
return;
}
// re-do any very recent actions that were incorrectly overwritten by this page
finishActions();
}
finished = true;
@ -787,11 +800,11 @@ public class NBSyncService extends Service {
if (HousekeepingRunning) return context.getResources().getString(R.string.sync_status_housekeeping);
if (ActionsRunning||RecountsRunning) return context.getResources().getString(R.string.sync_status_actions);
if (FFSyncRunning) return context.getResources().getString(R.string.sync_status_ffsync);
if (CleanupService.running()) return context.getResources().getString(R.string.sync_status_cleanup);
if (StorySyncRunning) return context.getResources().getString(R.string.sync_status_stories);
if (UnreadsService.running()) return String.format(context.getResources().getString(R.string.sync_status_unreads), UnreadsService.getPendingCount());
if (OriginalTextService.running()) return String.format(context.getResources().getString(R.string.sync_status_text), OriginalTextService.getPendingCount());
if (ImagePrefetchService.running()) return String.format(context.getResources().getString(R.string.sync_status_images), ImagePrefetchService.getPendingCount());
if (CleanupService.running()) return context.getResources().getString(R.string.sync_status_cleanup);
return null;
}

View file

@ -162,6 +162,10 @@ public class UnreadsService extends SubService {
doMetadata = true;
}
public static boolean isDoMetadata() {
return doMetadata;
}
public static boolean running() {
return Running;
}

View file

@ -147,6 +147,10 @@ public class FeedUtils {
dbHelper.touchStory(story.storyHash);
if (story.read == read) { return; }
// tell the sync service we need to mark read
ReadingAction ra = (read ? ReadingAction.markStoryRead(story.storyHash) : ReadingAction.markStoryUnread(story.storyHash));
dbHelper.enqueueAction(ra);
// update the local object to show as read before DB is touched
story.read = read;
@ -154,9 +158,6 @@ public class FeedUtils {
Set<FeedSet> impactedFeeds = dbHelper.setStoryReadState(story, read);
NbActivity.updateAllActivities(NbActivity.UPDATE_STORY);
// tell the sync service we need to mark read
ReadingAction ra = (read ? ReadingAction.markStoryRead(story.storyHash) : ReadingAction.markStoryUnread(story.storyHash));
dbHelper.enqueueAction(ra);
triggerSync(context);
NBSyncService.addRecountCandidates(impactedFeeds);
}