mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
delete entries with no feeds
This commit is contained in:
@@ -40,6 +40,19 @@ public class DatabaseCleaner {
|
|||||||
log.info("cleanup done: {} feeds without subscriptions deleted", total);
|
log.info("cleanup done: {} feeds without subscriptions deleted", total);
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long cleanEntriesWithoutFeeds() {
|
||||||
|
|
||||||
|
long total = 0;
|
||||||
|
int deleted = -1;
|
||||||
|
do {
|
||||||
|
deleted = feedEntryDAO.deleteWithoutFeeds(100);
|
||||||
|
total += deleted;
|
||||||
|
log.info("removed {} entries without feeds", total);
|
||||||
|
} while (deleted != 0);
|
||||||
|
log.info("cleanup done: {} entries without feeds deleted", total);
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
public long cleanEntriesOlderThan(long value, TimeUnit unit) {
|
public long cleanEntriesOlderThan(long value, TimeUnit unit) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import javax.ejb.Stateless;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.JoinType;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import javax.persistence.criteria.SetJoin;
|
import javax.persistence.criteria.SetJoin;
|
||||||
|
|
||||||
@@ -88,4 +89,20 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
|||||||
delete(list);
|
delete(list);
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int deleteWithoutFeeds(int max) {
|
||||||
|
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||||
|
Root<FeedEntry> root = query.from(getType());
|
||||||
|
|
||||||
|
SetJoin<FeedEntry, Feed> join = root.join(FeedEntry_.feeds,
|
||||||
|
JoinType.LEFT);
|
||||||
|
query.where(builder.isNull(join.get(Feed_.id)));
|
||||||
|
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||||
|
q.setMaxResults(max);
|
||||||
|
|
||||||
|
List<FeedEntry> list = q.getResultList();
|
||||||
|
int deleted = list.size();
|
||||||
|
delete(list);
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,6 +249,8 @@ public class AdminREST extends AbstractResourceREST {
|
|||||||
Map<String, Long> map = Maps.newHashMap();
|
Map<String, Long> map = Maps.newHashMap();
|
||||||
map.put("feeds_without_subscriptions",
|
map.put("feeds_without_subscriptions",
|
||||||
cleaner.cleanFeedsWithoutSubscriptions());
|
cleaner.cleanFeedsWithoutSubscriptions());
|
||||||
|
map.put("entries_without_feeds",
|
||||||
|
cleaner.cleanEntriesWithoutFeeds());
|
||||||
return Response.ok(map).build();
|
return Response.ok(map).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user