From 3b69e3b02916475e8013475b779b568a00003ba7 Mon Sep 17 00:00:00 2001 From: Athou Date: Mon, 17 Mar 2014 06:18:36 +0100 Subject: [PATCH] actually remove entries for feeds --- .../com/commafeed/backend/ScheduledTasks.java | 1 - .../services/DatabaseCleaningService.java | 38 +++++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/commafeed/backend/ScheduledTasks.java b/src/main/java/com/commafeed/backend/ScheduledTasks.java index 991a3908..072709f1 100644 --- a/src/main/java/com/commafeed/backend/ScheduledTasks.java +++ b/src/main/java/com/commafeed/backend/ScheduledTasks.java @@ -41,7 +41,6 @@ public class ScheduledTasks { */ @Schedule(hour = "*", persistent = false) private void cleanFeedsAndContents() { - cleaner.cleanEntriesForFeedsWithoutSubscriptions(); cleaner.cleanFeedsWithoutSubscriptions(); cleaner.cleanContentsWithoutEntries(); } diff --git a/src/main/java/com/commafeed/backend/services/DatabaseCleaningService.java b/src/main/java/com/commafeed/backend/services/DatabaseCleaningService.java index a61a87b5..68ac1356 100644 --- a/src/main/java/com/commafeed/backend/services/DatabaseCleaningService.java +++ b/src/main/java/com/commafeed/backend/services/DatabaseCleaningService.java @@ -25,7 +25,7 @@ import com.commafeed.backend.model.FeedSubscription; */ @Slf4j public class DatabaseCleaningService { - + private static final int BATCH_SIZE = 100; @Inject @@ -46,36 +46,34 @@ public class DatabaseCleaningService { @Inject ApplicationSettingsService applicationSettingsService; - public long cleanEntriesForFeedsWithoutSubscriptions() { - log.info("cleaning entries for feeds without subscriptions"); - long total = 0; - int deleted = 0; - do { - deleted = 0; - List feeds = feedDAO.findWithoutSubscriptions(1); - for (Feed feed : feeds) { - deleted += feedEntryDAO.delete(feed, BATCH_SIZE); - total += deleted; - log.info("removed {} entries for feeds without subscriptions", total); - } - } while (deleted != 0); - log.info("cleanup done: {} entries for feeds without subscriptions deleted", total); - return total; - } - public long cleanFeedsWithoutSubscriptions() { log.info("cleaning feeds without subscriptions"); long total = 0; + long totalEntries = 0; int deleted = 0; do { - deleted = feedDAO.delete(feedDAO.findWithoutSubscriptions(1)); + List feeds = feedDAO.findWithoutSubscriptions(1); + totalEntries += cleanEntriesForFeedsWithoutSubscriptions(feeds); + deleted = feedDAO.delete(feeds); total += deleted; - log.info("removed {} feeds without subscriptions", total); + log.info("removed {} feeds without subscriptions ({} entries)", total, totalEntries); } while (deleted != 0); log.info("cleanup done: {} feeds without subscriptions deleted", total); return total; } + private long cleanEntriesForFeedsWithoutSubscriptions(List feeds) { + long total = 0; + for (Feed feed : feeds) { + int deleted = 0; + do { + deleted = feedEntryDAO.delete(feed, BATCH_SIZE); + total += deleted; + } while (deleted != 0); + } + return total; + } + public long cleanContentsWithoutEntries() { log.info("cleaning contents without entries"); long total = 0;