mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-20 10:43:37 +00:00
batch guid existence check on feed refresh
Instead of querying the database once per entry to check if it already exists, fetch all existing guids for a feed in a single query upfront and filter new entries in memory before the per-entry loop. The per-entry findExisting call inside addEntry is kept as a safety net for concurrent inserts, but is now only reached for new entries. Profiling in real usage showed a ~50% reduction in guidHash queries, with the check falling from the most expensive query to sixth in the ranking.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.commafeed.backend.dao;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import jakarta.persistence.EntityManager;
|
||||
@@ -26,6 +28,10 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
||||
return query().select(ENTRY).from(ENTRY).where(ENTRY.guidHash.eq(guidHash), ENTRY.feed.eq(feed)).limit(1).fetchOne();
|
||||
}
|
||||
|
||||
public Set<String> findExistingGuids(Feed feed) {
|
||||
return new HashSet<>(query().select(ENTRY.guidHash).from(ENTRY).where(ENTRY.feed.eq(feed)).fetch());
|
||||
}
|
||||
|
||||
public List<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max, boolean keepStarredEntries) {
|
||||
NumberExpression<Long> count = ENTRY.id.count();
|
||||
JPAQuery<Tuple> query = query().select(ENTRY.feed.id, count).from(ENTRY);
|
||||
|
||||
Reference in New Issue
Block a user