mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-24 04:57:50 +00:00
Use batched IN clause for GUID existence check during feed refresh
Instead of fetching all existing GUID hashes for a feed from the database only check the GUIDs present in the current feed XML using a SQL IN clause. GUIDs are partitioned into batches of 1000. Also adds an integration test verifying that refreshing an up-to-date feed does not create duplicate entries.
This commit is contained in:
@@ -129,8 +129,16 @@ public class FeedRefreshUpdater {
|
||||
Map<FeedSubscription, List<FeedEntry>> insertedUnreadEntriesBySubscription = new HashMap<>();
|
||||
|
||||
if (!entries.isEmpty()) {
|
||||
Set<String> existingGuids = unitOfWork.call(() -> feedEntryDAO.findExistingGuids(feed));
|
||||
List<Entry> newEntries = entries.stream().filter(e -> !existingGuids.contains(Digests.sha1Hex(e.guid()))).toList();
|
||||
Map<String, Entry> entriesByGuidHash = new HashMap<>();
|
||||
for (Entry entry : entries) {
|
||||
entriesByGuidHash.put(Digests.sha1Hex(entry.guid()), entry);
|
||||
}
|
||||
Set<String> existingGuids = unitOfWork.call(() -> feedEntryDAO.findExistingGuids(feed, entriesByGuidHash.keySet()));
|
||||
List<Entry> newEntries = entriesByGuidHash.entrySet()
|
||||
.stream()
|
||||
.filter(e -> !existingGuids.contains(e.getKey()))
|
||||
.map(Map.Entry::getValue)
|
||||
.toList();
|
||||
|
||||
List<FeedSubscription> subscriptions = null;
|
||||
for (Entry entry : newEntries) {
|
||||
|
||||
Reference in New Issue
Block a user