multiple feeds may have the same url hash

This commit is contained in:
Athou
2024-01-07 15:04:46 +01:00
parent 789857b09f
commit da4143fa13

View File

@@ -9,7 +9,6 @@ import org.hibernate.SessionFactory;
import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.QFeed; import com.commafeed.backend.model.QFeed;
import com.commafeed.backend.model.QFeedSubscription; import com.commafeed.backend.model.QFeedSubscription;
import com.google.common.collect.Iterables;
import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQuery;
@@ -45,12 +44,13 @@ public class FeedDAO extends GenericDAO<Feed> {
} }
public Feed findByUrl(String normalizedUrl, String normalizedUrlHash) { public Feed findByUrl(String normalizedUrl, String normalizedUrlHash) {
List<Feed> feeds = query().selectFrom(feed).where(feed.normalizedUrlHash.eq(normalizedUrlHash)).fetch(); return query().selectFrom(feed)
Feed feed = Iterables.getFirst(feeds, null); .where(feed.normalizedUrlHash.eq(normalizedUrlHash))
if (feed != null && StringUtils.equals(normalizedUrl, feed.getNormalizedUrl())) { .fetch()
return feed; .stream()
} .filter(f -> StringUtils.equals(normalizedUrl, f.getNormalizedUrl()))
return null; .findFirst()
.orElse(null);
} }
public List<Feed> findWithoutSubscriptions(int max) { public List<Feed> findWithoutSubscriptions(int max) {