use join to speed up cleanup

This commit is contained in:
Athou
2024-08-16 15:45:17 +02:00
parent b333e8d90a
commit 5b77860189

View File

@@ -5,8 +5,6 @@ import java.util.List;
import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.QFeedEntry;
import com.commafeed.backend.model.QFeedEntryContent;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.JPQLSubQuery;
import jakarta.inject.Singleton;
import jakarta.persistence.EntityManager;
@@ -26,9 +24,13 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
}
public long deleteWithoutEntries(int max) {
JPQLSubQuery<Integer> subQuery = JPAExpressions.selectOne().from(ENTRY).where(ENTRY.content.id.eq(CONTENT.id));
List<Long> ids = query().select(CONTENT.id).from(CONTENT).where(subQuery.notExists()).limit(max).fetch();
List<Long> ids = query().select(CONTENT.id)
.from(CONTENT)
.leftJoin(ENTRY)
.on(ENTRY.content.id.eq(CONTENT.id))
.where(ENTRY.id.isNull())
.limit(max)
.fetch();
return deleteQuery(CONTENT).where(CONTENT.id.in(ids)).execute();
}
}