more database cleanup tasks

This commit is contained in:
Athou
2013-11-14 12:56:08 +01:00
parent 2a62ccff11
commit 4f284165c2
4 changed files with 16 additions and 5 deletions

View File

@@ -26,13 +26,22 @@ public class ScheduledTasks {
DatabaseCleaningService cleaner;
/**
* clean old read statuses, runs every day at midnight
* clean old read statuses
*/
@Schedule(hour = "0", persistent = false)
@Schedule(hour = "*", persistent = false)
private void cleanupOldStatuses() {
Date threshold = applicationSettingsService.getUnreadThreshold();
if (threshold != null) {
cleaner.cleanStatusesOlderThan(threshold);
}
}
/**
* clean feeds without subscriptions, then clean contents without entries
*/
@Schedule(hour = "*", persistent = false)
private void cleanFeedsAndContents() {
cleaner.cleanFeedsWithoutSubscriptions();
cleaner.cleanContentsWithoutEntries();
}
}

View File

@@ -107,7 +107,6 @@ public class FeedDAO extends GenericDAO<Feed> {
List<Feed> list = q.getResultList();
int deleted = list.size();
delete(list);
return deleted;

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.dao;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
@@ -15,6 +16,7 @@ import com.commafeed.backend.model.FeedEntryContent_;
import com.commafeed.backend.model.FeedEntry_;
import com.google.common.collect.Iterables;
@Stateless
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
public Long findExisting(String contentHash, String titleHash) {
@@ -44,6 +46,7 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
List<FeedEntryContent> list = q.getResultList();
int deleted = list.size();
delete(list);
return deleted;
}

View File

@@ -64,9 +64,9 @@ public class DatabaseCleaningService {
do {
deleted = feedEntryContentDAO.deleteWithoutEntries(10);
total += deleted;
log.info("removed {} feeds without subscriptions", total);
log.info("removed {} entries without feeds", total);
} while (deleted != 0);
log.info("cleanup done: {} feeds without subscriptions deleted", total);
log.info("cleanup done: {} entries without feeds deleted", total);
return total;
}