mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
gate only story cleanup behind cooldown so cache cleanup is immediate
This commit is contained in:
parent
3fdac7eb10
commit
d0fb4de8ce
4 changed files with 28 additions and 4 deletions
|
@ -149,6 +149,7 @@ public class BlurDatabaseHelper {
|
|||
" AND " + DatabaseConstants.STORY_TEXT_STORY_HASH + " NOT IN " +
|
||||
"( SELECT " + DatabaseConstants.READING_SESSION_STORY_HASH + " FROM " + DatabaseConstants.READING_SESSION_TABLE + ")",
|
||||
new String[]{Long.toString(cutoffDate.getTime().getTime())});
|
||||
com.newsblur.util.Log.d(this, "cleaned up ancient stories: " + count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,6 +164,7 @@ public class BlurDatabaseHelper {
|
|||
" AND " + DatabaseConstants.STORY_TEXT_STORY_HASH + " NOT IN " +
|
||||
"( SELECT " + DatabaseConstants.READING_SESSION_STORY_HASH + " FROM " + DatabaseConstants.READING_SESSION_TABLE + ")",
|
||||
null);
|
||||
com.newsblur.util.Log.d(this, "cleaned up read stories: " + count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,13 @@ public class CleanupService extends SubService {
|
|||
protected void exec() {
|
||||
gotWork();
|
||||
|
||||
com.newsblur.util.Log.d(this.getClass().getName(), "cleaning up old stories");
|
||||
parent.dbHelper.cleanupVeryOldStories();
|
||||
if (!PrefsUtils.isKeepOldStories(parent)) {
|
||||
parent.dbHelper.cleanupReadStories();
|
||||
if (PrefsUtils.isTimeToCleanup(parent)) {
|
||||
com.newsblur.util.Log.d(this.getClass().getName(), "cleaning up old stories");
|
||||
parent.dbHelper.cleanupVeryOldStories();
|
||||
if (!PrefsUtils.isKeepOldStories(parent)) {
|
||||
parent.dbHelper.cleanupReadStories();
|
||||
}
|
||||
PrefsUtils.updateLastCleanupTime(parent);
|
||||
}
|
||||
|
||||
com.newsblur.util.Log.d(this.getClass().getName(), "cleaning up old story texts");
|
||||
|
|
|
@ -34,6 +34,9 @@ public class AppConstants {
|
|||
// how often to rebuild the DB
|
||||
public static final long VACUUM_TIME_MILLIS = 12L * 60L * 60L * 1000L;
|
||||
|
||||
// how often to clean up stories from the DB
|
||||
public static final long CLEANUP_TIME_MILLIS = 6L * 60L * 60L * 1000L;
|
||||
|
||||
// how often to trigger the BG service. slightly longer than how often we will find new stories,
|
||||
// to account for the fact that it is approximate, and missing a cycle is bad.
|
||||
public static final long BG_SERVICE_CYCLE_MILLIS = AUTO_SYNC_TIME_MILLIS + 30L * 1000L;
|
||||
|
|
|
@ -318,6 +318,22 @@ public class PrefsUtils {
|
|||
prefs.edit().putLong(PrefConstants.LAST_VACUUM_TIME, (new Date()).getTime()).commit();
|
||||
}
|
||||
|
||||
public static boolean isTimeToCleanup(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
long lastTime = prefs.getLong(PrefConstants.LAST_CLEANUP_TIME, 1L);
|
||||
long nowTime = (new Date()).getTime();
|
||||
if ( (lastTime + AppConstants.CLEANUP_TIME_MILLIS) < nowTime ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLastCleanupTime(Context context) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
prefs.edit().putLong(PrefConstants.LAST_CLEANUP_TIME, (new Date()).getTime()).commit();
|
||||
}
|
||||
|
||||
public static StoryOrder getStoryOrderForFeed(Context context, String feedId) {
|
||||
SharedPreferences prefs = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
|
||||
return StoryOrder.valueOf(prefs.getString(PrefConstants.FEED_STORY_ORDER_PREFIX + feedId, getDefaultStoryOrder(prefs).toString()));
|
||||
|
|
Loading…
Add table
Reference in a new issue