we don't need the user we already have the subscription

This commit is contained in:
Athou
2024-07-01 13:55:50 +02:00
parent 9b1c6a371e
commit 93acc9ded1
2 changed files with 7 additions and 9 deletions

View File

@@ -201,17 +201,15 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return statuses;
}
public UnreadCount getUnreadCount(User user, FeedSubscription sub) {
public UnreadCount getUnreadCount(FeedSubscription sub) {
JPAQuery<Tuple> query = query().select(entry.count(), entry.updated.max())
.from(entry)
.join(entry.feed, feed)
.join(subscription)
.on(subscription.feed.eq(feed).and(subscription.user.eq(user)))
.on(subscription.feed.eq(feed).and(subscription.eq(sub)))
.leftJoin(status)
.on(status.entry.eq(entry).and(status.subscription.eq(subscription)))
.where(subscription.eq(sub));
query.where(buildUnreadPredicate());
.on(status.entry.eq(entry).and(status.subscription.eq(sub)))
.where(buildUnreadPredicate());
Tuple tuple = query.fetchOne();
Long count = tuple.get(entry.count());

View File

@@ -119,14 +119,14 @@ public class FeedSubscriptionService {
}
public Map<Long, UnreadCount> getUnreadCount(User user) {
return feedSubscriptionDAO.findAll(user).stream().collect(Collectors.toMap(FeedSubscription::getId, s -> getUnreadCount(user, s)));
return feedSubscriptionDAO.findAll(user).stream().collect(Collectors.toMap(FeedSubscription::getId, this::getUnreadCount));
}
private UnreadCount getUnreadCount(User user, FeedSubscription sub) {
private UnreadCount getUnreadCount(FeedSubscription sub) {
UnreadCount count = cache.getUnreadCount(sub);
if (count == null) {
log.debug("unread count cache miss for {}", Models.getId(sub));
count = feedEntryStatusDAO.getUnreadCount(user, sub);
count = feedEntryStatusDAO.getUnreadCount(sub);
cache.setUnreadCount(sub, count);
}
return count;