mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
revamp cache service
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
package com.commafeed.backend.cache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
|
||||
public abstract class CacheService {
|
||||
|
||||
// feed entries for faster refresh
|
||||
public abstract List<String> getLastEntries(Feed feed);
|
||||
|
||||
public abstract void setLastEntries(Feed feed, List<String> entries);
|
||||
@@ -20,14 +21,25 @@ public abstract class CacheService {
|
||||
return DigestUtils.sha1Hex(entry.getGuid() + entry.getUrl());
|
||||
}
|
||||
|
||||
public abstract Category getRootCategory(User user);
|
||||
// user categories
|
||||
public abstract List<FeedCategory> getUserCategories(User user);
|
||||
|
||||
public abstract void setRootCategory(User user, Category category);
|
||||
public abstract void setUserCategories(User user, List<FeedCategory> categories);
|
||||
|
||||
public abstract Map<Long, Long> getUnreadCounts(User user);
|
||||
public abstract void invalidateUserCategories(User user);
|
||||
|
||||
public abstract void setUnreadCounts(User user, Map<Long, Long> map);
|
||||
// subscriptions
|
||||
public abstract List<FeedSubscription> getUserSubscriptions(User user);
|
||||
|
||||
public abstract void invalidateUserData(User... users);
|
||||
public abstract void setUserSubscriptions(User user, List<FeedSubscription> subs);
|
||||
|
||||
public abstract void invalidateUserSubscriptions(User user);
|
||||
|
||||
// unread count
|
||||
public abstract Long getUnreadCount(FeedSubscription sub);
|
||||
|
||||
public abstract void setUnreadCount(FeedSubscription sub, Long count);
|
||||
|
||||
public abstract void invalidateUnreadCount(FeedSubscription... subs);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.commafeed.backend.cache;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Alternative;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
|
||||
@Alternative
|
||||
@ApplicationScoped
|
||||
@@ -25,27 +25,47 @@ public class NoopCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getRootCategory(User user) {
|
||||
public Long getUnreadCount(FeedSubscription sub) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRootCategory(User user, Category category) {
|
||||
public void setUnreadCount(FeedSubscription sub, Long count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Long> getUnreadCounts(User user) {
|
||||
public List<FeedCategory> getUserCategories(User user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnreadCounts(User user, Map<Long, Long> map) {
|
||||
public void setUserCategories(User user, List<FeedCategory> categories) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserData(User... users) {
|
||||
public void invalidateUserCategories(User user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeedSubscription> getUserSubscriptions(User user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserSubscriptions(User user, List<FeedSubscription> subs) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserSubscriptions(User user) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUnreadCount(FeedSubscription... subs) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.commafeed.backend.cache;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -17,12 +16,13 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.Models;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.MapType;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.google.api.client.util.Lists;
|
||||
|
||||
@Alternative
|
||||
@@ -30,9 +30,12 @@ import com.google.api.client.util.Lists;
|
||||
public class RedisCacheService extends CacheService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RedisCacheService.class);
|
||||
private static ObjectMapper mapper = new ObjectMapper();
|
||||
private static CollectionType TYPE_LIST_CATEGORIES = mapper.getTypeFactory().constructCollectionType(List.class, FeedCategory.class);
|
||||
private static CollectionType TYPE_LIST_SUBSCRIPTIONS = mapper.getTypeFactory().constructCollectionType(List.class,
|
||||
FeedSubscription.class);
|
||||
|
||||
private JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public List<String> getLastEntries(Feed feed) {
|
||||
@@ -69,32 +72,32 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getRootCategory(User user) {
|
||||
Category cat = null;
|
||||
public List<FeedCategory> getUserCategories(User user) {
|
||||
List<FeedCategory> cats = null;
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisRootCategoryKey(user);
|
||||
String key = buildRedisUserCategoriesKey(user);
|
||||
String json = jedis.get(key);
|
||||
if (json != null) {
|
||||
cat = mapper.readValue(json, Category.class);
|
||||
cats = mapper.readValue(json, TYPE_LIST_CATEGORIES);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
return cat;
|
||||
return cats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRootCategory(User user, Category category) {
|
||||
public void setUserCategories(User user, List<FeedCategory> categories) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisRootCategoryKey(user);
|
||||
String key = buildRedisUserCategoriesKey(user);
|
||||
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
pipe.del(key);
|
||||
pipe.set(key, mapper.writeValueAsString(category));
|
||||
pipe.set(key, mapper.writeValueAsString(categories));
|
||||
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
|
||||
pipe.sync();
|
||||
} catch (JsonProcessingException e) {
|
||||
@@ -105,33 +108,32 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Long> getUnreadCounts(User user) {
|
||||
Map<Long, Long> map = null;
|
||||
public List<FeedSubscription> getUserSubscriptions(User user) {
|
||||
List<FeedSubscription> subs = null;
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUnreadCountKey(user);
|
||||
String key = buildRedisUserSubscriptionsKey(user);
|
||||
String json = jedis.get(key);
|
||||
if (json != null) {
|
||||
MapType type = mapper.getTypeFactory().constructMapType(Map.class, Long.class, Long.class);
|
||||
map = mapper.readValue(json, type);
|
||||
subs = mapper.readValue(json, TYPE_LIST_SUBSCRIPTIONS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
return map;
|
||||
return subs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnreadCounts(User user, Map<Long, Long> map) {
|
||||
public void setUserSubscriptions(User user, List<FeedSubscription> subs) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUnreadCountKey(user);
|
||||
String key = buildRedisUserSubscriptionsKey(user);
|
||||
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
pipe.del(key);
|
||||
pipe.set(key, mapper.writeValueAsString(map));
|
||||
pipe.set(key, mapper.writeValueAsString(subs));
|
||||
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
|
||||
pipe.sync();
|
||||
} catch (JsonProcessingException e) {
|
||||
@@ -142,15 +144,71 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserData(User... users) {
|
||||
public Long getUnreadCount(FeedSubscription sub) {
|
||||
Long count = null;
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUnreadCountKey(sub);
|
||||
String countString = jedis.get(key);
|
||||
if (countString != null) {
|
||||
count = Long.valueOf(countString);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnreadCount(FeedSubscription sub, Long count) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUnreadCountKey(sub);
|
||||
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
pipe.del(key);
|
||||
pipe.set(key, String.valueOf(count));
|
||||
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
|
||||
pipe.sync();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserCategories(User user) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserCategoriesKey(user);
|
||||
jedis.del(key);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserSubscriptions(User user) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserSubscriptionsKey(user);
|
||||
jedis.del(key);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUnreadCount(FeedSubscription... subs) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
if (users != null) {
|
||||
for (User user : users) {
|
||||
String key = buildRedisRootCategoryKey(user);
|
||||
pipe.del(key);
|
||||
key = buildRedisUnreadCountKey(user);
|
||||
if (subs != null) {
|
||||
for (FeedSubscription sub : subs) {
|
||||
String key = buildRedisUnreadCountKey(sub);
|
||||
pipe.del(key);
|
||||
}
|
||||
}
|
||||
@@ -160,16 +218,20 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
}
|
||||
|
||||
private String buildRedisRootCategoryKey(User user) {
|
||||
return "root_cat:" + Models.getId(user);
|
||||
}
|
||||
|
||||
private String buildRedisUnreadCountKey(User user) {
|
||||
return "unread_count:" + Models.getId(user);
|
||||
}
|
||||
|
||||
private String buildRedisEntryKey(Feed feed) {
|
||||
return "feed:" + feed.getId();
|
||||
return "f:" + Models.getId(feed);
|
||||
}
|
||||
|
||||
private String buildRedisUserCategoriesKey(User user) {
|
||||
return "c:" + Models.getId(user);
|
||||
}
|
||||
|
||||
private String buildRedisUserSubscriptionsKey(User user) {
|
||||
return "s:" + Models.getId(user);
|
||||
}
|
||||
|
||||
private String buildRedisUnreadCountKey(FeedSubscription sub) {
|
||||
return "u:" + Models.getId(sub);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,28 +266,4 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
|
||||
}
|
||||
|
||||
public void markSubscriptionEntries(List<FeedSubscription> subscriptions, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findBySubscriptions(subscriptions, true, null, null, -1, -1, null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
public void markStarredEntries(User user, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findStarred(user, null, -1, -1, null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
private void markList(List<FeedEntryStatus> statuses, Date olderThan) {
|
||||
List<FeedEntryStatus> list = Lists.newArrayList();
|
||||
for (FeedEntryStatus status : statuses) {
|
||||
if (!status.isRead()) {
|
||||
Date inserted = status.getEntry().getInserted();
|
||||
if (olderThan == null || inserted == null || olderThan.after(inserted)) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
saveOrUpdate(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public class OPMLImporter {
|
||||
log.error("error while importing {}: {}", outline.getXmlUrl(), e.getMessage());
|
||||
}
|
||||
}
|
||||
cache.invalidateUserData(user);
|
||||
cache.invalidateUserCategories(user);
|
||||
cache.invalidateUserSubscriptions(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.Models;
|
||||
import com.commafeed.backend.model.User;
|
||||
|
||||
public class FeedCategoryService {
|
||||
private static Logger log = LoggerFactory.getLogger(FeedSubscriptionService.class);
|
||||
|
||||
@Inject
|
||||
FeedCategoryDAO feedCategoryDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
public List<FeedCategory> getCategories(User user) {
|
||||
List<FeedCategory> list = cache.getUserCategories(user);
|
||||
if (list == null) {
|
||||
log.debug("cat list miss for {}", Models.getId(user));
|
||||
list = feedCategoryDAO.findAll(user);
|
||||
cache.setUserCategories(user, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -10,6 +14,7 @@ import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@Stateless
|
||||
public class FeedEntryService {
|
||||
@@ -23,6 +28,9 @@ public class FeedEntryService {
|
||||
@Inject
|
||||
FeedEntryDAO feedEntryDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
public void markEntry(User user, Long entryId, Long subscriptionId, boolean read) {
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(user, subscriptionId);
|
||||
if (sub == null) {
|
||||
@@ -38,6 +46,7 @@ public class FeedEntryService {
|
||||
if (status.isMarkable()) {
|
||||
status.setRead(read);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
cache.invalidateUnreadCount(sub);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +66,29 @@ public class FeedEntryService {
|
||||
status.setStarred(starred);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
}
|
||||
|
||||
public void markSubscriptionEntries(List<FeedSubscription> subscriptions, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, -1, -1, null, false);
|
||||
markList(statuses, olderThan);
|
||||
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
||||
}
|
||||
|
||||
public void markStarredEntries(User user, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findStarred(user, null, -1, -1, null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
private void markList(List<FeedEntryStatus> statuses, Date olderThan) {
|
||||
List<FeedEntryStatus> list = Lists.newArrayList();
|
||||
for (FeedEntryStatus status : statuses) {
|
||||
if (!status.isRead()) {
|
||||
Date inserted = status.getEntry().getInserted();
|
||||
if (olderThan == null || inserted == null || olderThan.after(inserted)) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
feedEntryStatusDAO.saveOrUpdate(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,20 +80,48 @@ public class FeedSubscriptionService {
|
||||
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||
|
||||
taskGiver.add(feed);
|
||||
cache.invalidateUserSubscriptions(user);
|
||||
return feed;
|
||||
}
|
||||
|
||||
public boolean unsubscribe(User user, Long subId){
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(user, subId);
|
||||
if (sub != null) {
|
||||
feedSubscriptionDAO.delete(sub);
|
||||
cache.invalidateUserSubscriptions(user);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<FeedSubscription> getSubscriptions(User user) {
|
||||
List<FeedSubscription> list = cache.getUserSubscriptions(user);
|
||||
if (list == null) {
|
||||
log.debug("sub list miss for {}", Models.getId(user));
|
||||
list = feedSubscriptionDAO.findAll(user);
|
||||
cache.setUserSubscriptions(user, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public Long getUnreadCount(FeedSubscription sub) {
|
||||
Long count = cache.getUnreadCount(sub);
|
||||
if (count == null) {
|
||||
log.debug("unread count cache miss for {}", Models.getId(sub));
|
||||
count = feedEntryStatusDAO.getUnreadCount(sub);
|
||||
cache.setUnreadCount(sub, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
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));
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||
map = Maps.newHashMap();
|
||||
for (FeedSubscription sub : subs) {
|
||||
map.put(sub.getId(), feedEntryStatusDAO.getUnreadCount(sub));
|
||||
}
|
||||
cache.setUnreadCounts(user, map);
|
||||
Map<Long, Long> map = Maps.newHashMap();
|
||||
List<FeedSubscription> subs = getSubscriptions(user);
|
||||
for (FeedSubscription sub : subs) {
|
||||
map.put(sub.getId(), getUnreadCount(sub));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ public class FeedUpdateService {
|
||||
}
|
||||
feedEntryDAO.saveOrUpdate(entry);
|
||||
metricsBean.entryInserted();
|
||||
cache.invalidateUserData(users.toArray(new User[0]));
|
||||
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.commafeed.backend.services.FeedCategoryService;
|
||||
import com.commafeed.backend.services.FeedEntryService;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
@@ -68,6 +70,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||
|
||||
@Inject
|
||||
FeedEntryService feedEntryService;
|
||||
|
||||
@Inject
|
||||
FeedCategoryDAO feedCategoryDAO;
|
||||
|
||||
@@ -77,6 +82,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@@ -206,17 +214,16 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
||||
|
||||
if (ALL.equals(req.getId())) {
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
|
||||
feedEntryStatusDAO.markSubscriptionEntries(subscriptions, olderThan);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionService.getSubscriptions(getUser());
|
||||
feedEntryService.markSubscriptionEntries(subscriptions, olderThan);
|
||||
} else if (STARRED.equals(req.getId())) {
|
||||
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
|
||||
feedEntryService.markStarredEntries(getUser(), olderThan);
|
||||
} else {
|
||||
FeedCategory parent = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getId()));
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), parent);
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(getUser(), categories);
|
||||
feedEntryStatusDAO.markSubscriptionEntries(subs, olderThan);
|
||||
feedEntryService.markSubscriptionEntries(subs, olderThan);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -238,7 +245,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
cat.setParent(parent);
|
||||
}
|
||||
feedCategoryDAO.saveOrUpdate(cat);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@@ -266,7 +273,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
feedCategoryDAO.saveOrUpdate(categories);
|
||||
|
||||
feedCategoryDAO.delete(cat);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -322,7 +329,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -339,7 +346,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
category.setCollapsed(req.isCollapse());
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -364,18 +371,15 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
public Response getSubscriptions() {
|
||||
User user = getUser();
|
||||
|
||||
Category root = cache.getRootCategory(user);
|
||||
if (root == null) {
|
||||
log.debug("root category cache miss for {}", user.getName());
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
|
||||
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
|
||||
Category root = null;
|
||||
List<FeedCategory> categories = feedCategoryService.getCategories(user);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionService.getSubscriptions(getUser());
|
||||
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
|
||||
|
||||
root = buildCategory(null, categories, subscriptions, unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
|
||||
root = buildCategory(null, categories, subscriptions, unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
cache.setRootCategory(user, root);
|
||||
}
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
@@ -44,9 +43,6 @@ public class EntryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Path("/mark")
|
||||
@POST
|
||||
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
|
||||
@@ -56,7 +52,6 @@ public class EntryREST extends AbstractResourceREST {
|
||||
Preconditions.checkNotNull(req.getFeedId());
|
||||
|
||||
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()), req.getFeedId(), req.isRead());
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.commafeed.backend.services.FeedEntryService;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
@@ -97,6 +98,9 @@ public class FeedREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
FeedEntryService feedEntryService;
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@@ -274,9 +278,8 @@ public class FeedREST extends AbstractResourceREST {
|
||||
|
||||
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), Long.valueOf(req.getId()));
|
||||
if (subscription != null) {
|
||||
feedEntryStatusDAO.markSubscriptionEntries(Arrays.asList(subscription), olderThan);
|
||||
feedEntryService.markSubscriptionEntries(Arrays.asList(subscription), olderThan);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -353,7 +356,6 @@ public class FeedREST extends AbstractResourceREST {
|
||||
log.info("Failed to subscribe to URL {}: {}", url, e.getMessage());
|
||||
return Response.status(Status.SERVICE_UNAVAILABLE).entity("Failed to subscribe to URL " + url + ": " + e.getMessage()).build();
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -390,10 +392,8 @@ public class FeedREST extends AbstractResourceREST {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), req.getId());
|
||||
if (sub != null) {
|
||||
feedSubscriptionDAO.delete(sub);
|
||||
cache.invalidateUserData(getUser());
|
||||
boolean deleted = feedSubscriptionService.unsubscribe(getUser(), req.getId());
|
||||
if (deleted) {
|
||||
return Response.ok(Status.OK).build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -446,7 +446,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
} else {
|
||||
feedSubscriptionDAO.saveOrUpdate(subscription);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserSubscriptions(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -480,7 +480,6 @@ public class FeedREST extends AbstractResourceREST {
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.temporaryRedirect(URI.create(applicationSettingsService.get().getPublicUrl())).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import javax.ws.rs.core.Response.Status;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
import com.commafeed.backend.dao.UserRoleDAO;
|
||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||
@@ -58,9 +57,6 @@ public class UserREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
PasswordEncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@@ -200,7 +196,6 @@ public class UserREST extends AbstractResourceREST {
|
||||
return Response.status(Status.FORBIDDEN).build();
|
||||
}
|
||||
userService.unregister(getUser());
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user