mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
cache unread count
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.ApplicationException;
|
||||
import javax.inject.Inject;
|
||||
@@ -9,6 +10,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -19,12 +21,14 @@ import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.Models;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.google.api.client.util.Lists;
|
||||
|
||||
public class FeedSubscriptionService {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(FeedSubscriptionService.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(FeedSubscriptionService.class);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@ApplicationException
|
||||
@@ -52,6 +56,9 @@ public class FeedSubscriptionService {
|
||||
@Inject
|
||||
FeedRefreshTaskGiver taskGiver;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
public Feed subscribe(User user, String url, String title,
|
||||
FeedCategory category) {
|
||||
|
||||
@@ -83,7 +90,8 @@ public class FeedSubscriptionService {
|
||||
if (newSubscription) {
|
||||
try {
|
||||
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
||||
List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0, 10);
|
||||
List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0,
|
||||
10);
|
||||
for (FeedEntry entry : allEntries) {
|
||||
FeedEntryStatus status = new FeedEntryStatus();
|
||||
status.setEntry(entry);
|
||||
@@ -93,10 +101,22 @@ public class FeedSubscriptionService {
|
||||
}
|
||||
feedEntryStatusDAO.saveOrUpdate(statuses);
|
||||
} catch (Exception e) {
|
||||
log.error("could not fetch initial statuses when importing {} : {}", feed.getUrl(), e.getMessage());
|
||||
log.error(
|
||||
"could not fetch initial statuses when importing {} : {}",
|
||||
feed.getUrl(), e.getMessage());
|
||||
}
|
||||
}
|
||||
taskGiver.add(feed);
|
||||
return feed;
|
||||
}
|
||||
|
||||
public Map<Long, Long> getUnreadCount(User user) {
|
||||
Map<Long, Long> map = cache.getUnreadCounts(user);
|
||||
if (map == null) {
|
||||
log.debug("unread count cache miss for {}", Models.getId(user));
|
||||
map = feedEntryStatusDAO.getUnreadCount(user);
|
||||
cache.setUnreadCounts(user, map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user