forked from Archives/Athou_commafeed
more database cleanup tasks
This commit is contained in:
@@ -26,13 +26,22 @@ public class ScheduledTasks {
|
|||||||
DatabaseCleaningService cleaner;
|
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() {
|
private void cleanupOldStatuses() {
|
||||||
Date threshold = applicationSettingsService.getUnreadThreshold();
|
Date threshold = applicationSettingsService.getUnreadThreshold();
|
||||||
if (threshold != null) {
|
if (threshold != null) {
|
||||||
cleaner.cleanStatusesOlderThan(threshold);
|
cleaner.cleanStatusesOlderThan(threshold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean feeds without subscriptions, then clean contents without entries
|
||||||
|
*/
|
||||||
|
@Schedule(hour = "*", persistent = false)
|
||||||
|
private void cleanFeedsAndContents() {
|
||||||
|
cleaner.cleanFeedsWithoutSubscriptions();
|
||||||
|
cleaner.cleanContentsWithoutEntries();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ public class FeedDAO extends GenericDAO<Feed> {
|
|||||||
|
|
||||||
List<Feed> list = q.getResultList();
|
List<Feed> list = q.getResultList();
|
||||||
int deleted = list.size();
|
int deleted = list.size();
|
||||||
|
|
||||||
delete(list);
|
delete(list);
|
||||||
return deleted;
|
return deleted;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.commafeed.backend.dao;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Join;
|
import javax.persistence.criteria.Join;
|
||||||
@@ -15,6 +16,7 @@ import com.commafeed.backend.model.FeedEntryContent_;
|
|||||||
import com.commafeed.backend.model.FeedEntry_;
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
||||||
|
|
||||||
public Long findExisting(String contentHash, String titleHash) {
|
public Long findExisting(String contentHash, String titleHash) {
|
||||||
@@ -44,6 +46,7 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
|||||||
|
|
||||||
List<FeedEntryContent> list = q.getResultList();
|
List<FeedEntryContent> list = q.getResultList();
|
||||||
int deleted = list.size();
|
int deleted = list.size();
|
||||||
|
delete(list);
|
||||||
return deleted;
|
return deleted;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ public class DatabaseCleaningService {
|
|||||||
do {
|
do {
|
||||||
deleted = feedEntryContentDAO.deleteWithoutEntries(10);
|
deleted = feedEntryContentDAO.deleteWithoutEntries(10);
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} feeds without subscriptions", total);
|
log.info("removed {} entries without feeds", total);
|
||||||
} while (deleted != 0);
|
} while (deleted != 0);
|
||||||
log.info("cleanup done: {} feeds without subscriptions deleted", total);
|
log.info("cleanup done: {} entries without feeds deleted", total);
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user