rewrite query using not exists

This commit is contained in:
Athou
2015-04-23 08:55:47 +02:00
parent fc104b0b01
commit 4d71a8f3c2

View File

@@ -11,6 +11,7 @@ import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.QFeedEntry;
import com.commafeed.backend.model.QFeedEntryContent;
import com.google.common.collect.Iterables;
import com.mysema.query.jpa.hibernate.HibernateSubQuery;
@Singleton
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
@@ -30,8 +31,10 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
public int deleteWithoutEntries(int max) {
QFeedEntry entry = QFeedEntry.feedEntry;
List<FeedEntryContent> list = newQuery().from(content).leftJoin(content.entries, entry).where(entry.id.isNull()).limit(max)
.list(content);
HibernateSubQuery subQuery = new HibernateSubQuery().from(entry).where(entry.content.id.eq(content.id));
List<FeedEntryContent> list = newQuery().from(content).where(subQuery.notExists()).limit(max).list(content);
int deleted = list.size();
delete(list);
return deleted;