mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
delete operation does not support limit. limit on select and delete afterwards
This commit is contained in:
@@ -290,11 +290,17 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
|
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteOldStatuses(Date olderThan, int limit) {
|
public List<FeedEntryStatus> getOldStatuses(Date olderThan, int limit) {
|
||||||
Query query = em.createNamedQuery("Statuses.deleteOld");
|
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||||
query.setParameter("date", olderThan);
|
Root<FeedEntryStatus> root = query.from(getType());
|
||||||
query.setMaxResults(limit);
|
|
||||||
return query.executeUpdate();
|
Predicate p1 = builder.lessThan(root.get(FeedEntryStatus_.entryInserted), olderThan);
|
||||||
|
Predicate p2 = builder.isFalse(root.get(FeedEntryStatus_.starred));
|
||||||
|
|
||||||
|
query.where(p1, p2);
|
||||||
|
TypedQuery<FeedEntryStatus> q = em.createQuery(query);
|
||||||
|
q.setMaxResults(limit);
|
||||||
|
return q.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.commafeed.backend.services;
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -15,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.FeedEntryStatus;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,12 +103,15 @@ public class DatabaseCleaningService {
|
|||||||
public long cleanStatusesOlderThan(Date olderThan) {
|
public long cleanStatusesOlderThan(Date olderThan) {
|
||||||
log.info("cleaning old read statuses");
|
log.info("cleaning old read statuses");
|
||||||
long total = 0;
|
long total = 0;
|
||||||
int deleted = -1;
|
List<FeedEntryStatus> list = Collections.emptyList();
|
||||||
do {
|
do {
|
||||||
deleted = feedEntryStatusDAO.deleteOldStatuses(olderThan, 100);
|
list = feedEntryStatusDAO.getOldStatuses(olderThan, 100);
|
||||||
total += deleted;
|
if (!list.isEmpty()) {
|
||||||
log.info("cleaned {} old read statuses", total);
|
feedEntryStatusDAO.delete(list);
|
||||||
} while (deleted != 0);
|
total += list.size();
|
||||||
|
log.info("cleaned {} old read statuses", total);
|
||||||
|
}
|
||||||
|
} while (!list.isEmpty());
|
||||||
log.info("cleanup done: {} old read statuses deleted", total);
|
log.info("cleanup done: {} old read statuses deleted", total);
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user