mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
first clean entries then clean feeds
This commit is contained in:
@@ -41,6 +41,7 @@ public class ScheduledTasks {
|
|||||||
*/
|
*/
|
||||||
@Schedule(hour = "*", persistent = false)
|
@Schedule(hour = "*", persistent = false)
|
||||||
private void cleanFeedsAndContents() {
|
private void cleanFeedsAndContents() {
|
||||||
|
cleaner.cleanEntriesWithoutSubscriptions();
|
||||||
cleaner.cleanFeedsWithoutSubscriptions();
|
cleaner.cleanFeedsWithoutSubscriptions();
|
||||||
cleaner.cleanContentsWithoutEntries();
|
cleaner.cleanContentsWithoutEntries();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,14 +6,19 @@ import java.util.List;
|
|||||||
import javax.ejb.Stateless;
|
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.JoinType;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
import javax.persistence.criteria.SetJoin;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedEntry_;
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
|
import com.commafeed.backend.model.FeedSubscription_;
|
||||||
import com.commafeed.backend.model.Feed_;
|
import com.commafeed.backend.model.Feed_;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
@@ -37,6 +42,19 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
|||||||
return Iterables.getFirst(list, null);
|
return Iterables.getFirst(list, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FeedEntry> findWithoutSubscriptions(int max) {
|
||||||
|
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||||
|
Root<FeedEntry> root = query.from(getType());
|
||||||
|
|
||||||
|
Join<FeedEntry, Feed> feedJoin = root.join(FeedEntry_.feed);
|
||||||
|
SetJoin<Feed, FeedSubscription> subJoin = feedJoin.join(Feed_.subscriptions, JoinType.LEFT);
|
||||||
|
query.where(builder.isNull(subJoin.get(FeedSubscription_.id)));
|
||||||
|
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||||
|
q.setMaxResults(max);
|
||||||
|
|
||||||
|
return q.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
public int delete(Feed feed, int max) {
|
public int delete(Feed feed, int max) {
|
||||||
|
|
||||||
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.commafeed.backend.dao.FeedEntryDAO;
|
|||||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedEntryStatus;
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
|
|
||||||
@@ -45,14 +46,27 @@ public class DatabaseCleaningService {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
|
public long cleanEntriesWithoutSubscriptions() {
|
||||||
|
log.info("cleaning entries without subscriptions");
|
||||||
|
long total = 0;
|
||||||
|
int deleted = 0;
|
||||||
|
do {
|
||||||
|
List<FeedEntry> entries = feedEntryDAO.findWithoutSubscriptions(BATCH_SIZE);
|
||||||
|
deleted = feedEntryDAO.delete(entries);
|
||||||
|
total += deleted;
|
||||||
|
log.info("removed {} entries without subscriptions", total);
|
||||||
|
} while (deleted != 0);
|
||||||
|
log.info("cleanup done: {} entries without subscriptions deleted", total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
public long cleanFeedsWithoutSubscriptions() {
|
public long cleanFeedsWithoutSubscriptions() {
|
||||||
log.info("cleaning feeds without subscriptions");
|
log.info("cleaning feeds without subscriptions");
|
||||||
long total = 0;
|
long total = 0;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
do {
|
do {
|
||||||
List<Feed> feeds = feedDAO.findWithoutSubscriptions(1);
|
List<Feed> feeds = feedDAO.findWithoutSubscriptions(BATCH_SIZE);
|
||||||
cleanEntriesForFeedsWithoutSubscriptions(feeds);
|
|
||||||
deleted = feedDAO.delete(feeds);
|
deleted = feedDAO.delete(feeds);
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} feeds without subscriptions", total);
|
log.info("removed {} feeds without subscriptions", total);
|
||||||
@@ -61,19 +75,6 @@ public class DatabaseCleaningService {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long cleanEntriesForFeedsWithoutSubscriptions(List<Feed> feeds) {
|
|
||||||
long total = 0;
|
|
||||||
for (Feed feed : feeds) {
|
|
||||||
int deleted = 0;
|
|
||||||
do {
|
|
||||||
deleted = feedEntryDAO.delete(feed, BATCH_SIZE);
|
|
||||||
total += deleted;
|
|
||||||
log.info("removed {} entries for feed {}", total, feed.getId());
|
|
||||||
} while (deleted != 0);
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long cleanContentsWithoutEntries() {
|
public long cleanContentsWithoutEntries() {
|
||||||
log.info("cleaning contents without entries");
|
log.info("cleaning contents without entries");
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user