mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
revert part of caching mechanism
This commit is contained in:
@@ -5,10 +5,10 @@ import java.util.List;
|
||||
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 {
|
||||
|
||||
@@ -22,18 +22,11 @@ public abstract class CacheService {
|
||||
}
|
||||
|
||||
// user categories
|
||||
public abstract List<FeedCategory> getUserCategories(User user);
|
||||
public abstract Category getUserRootCategory(User user);
|
||||
|
||||
public abstract void setUserCategories(User user, List<FeedCategory> categories);
|
||||
public abstract void setUserRootCategory(User user, Category category);
|
||||
|
||||
public abstract void invalidateUserCategories(User user);
|
||||
|
||||
// subscriptions
|
||||
public abstract List<FeedSubscription> getUserSubscriptions(User user);
|
||||
|
||||
public abstract void setUserSubscriptions(User user, List<FeedSubscription> subs);
|
||||
|
||||
public abstract void invalidateUserSubscriptions(User user);
|
||||
public abstract void invalidateUserRootCategory(User... users);
|
||||
|
||||
// unread count
|
||||
public abstract Long getUnreadCount(FeedSubscription sub);
|
||||
|
||||
@@ -7,9 +7,9 @@ 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
|
||||
@@ -34,39 +34,24 @@ public class NoopCacheService extends CacheService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeedCategory> getUserCategories(User user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserCategories(User user, List<FeedCategory> categories) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getUserRootCategory(User user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserRootCategory(User user, Category category) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserRootCategory(User... users) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@ 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.CollectionType;
|
||||
import com.google.api.client.util.Lists;
|
||||
|
||||
@Alternative
|
||||
@@ -31,9 +30,6 @@ 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");
|
||||
|
||||
@@ -72,68 +68,32 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeedCategory> getUserCategories(User user) {
|
||||
List<FeedCategory> cats = null;
|
||||
public Category getUserRootCategory(User user) {
|
||||
Category cat = null;
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserCategoriesKey(user);
|
||||
String key = buildRedisUserRootCategoryKey(user);
|
||||
String json = jedis.get(key);
|
||||
if (json != null) {
|
||||
cats = mapper.readValue(json, TYPE_LIST_CATEGORIES);
|
||||
cat = mapper.readValue(json, Category.class);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
return cats;
|
||||
return cat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserCategories(User user, List<FeedCategory> categories) {
|
||||
public void setUserRootCategory(User user, Category category) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserCategoriesKey(user);
|
||||
String key = buildRedisUserRootCategoryKey(user);
|
||||
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
pipe.del(key);
|
||||
pipe.set(key, mapper.writeValueAsString(categories));
|
||||
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
|
||||
pipe.sync();
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeedSubscription> getUserSubscriptions(User user) {
|
||||
List<FeedSubscription> subs = null;
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserSubscriptionsKey(user);
|
||||
String json = jedis.get(key);
|
||||
if (json != null) {
|
||||
subs = mapper.readValue(json, TYPE_LIST_SUBSCRIPTIONS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
return subs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserSubscriptions(User user, List<FeedSubscription> subs) {
|
||||
Jedis jedis = pool.getResource();
|
||||
try {
|
||||
String key = buildRedisUserSubscriptionsKey(user);
|
||||
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
pipe.del(key);
|
||||
pipe.set(key, mapper.writeValueAsString(subs));
|
||||
pipe.set(key, mapper.writeValueAsString(category));
|
||||
pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30));
|
||||
pipe.sync();
|
||||
} catch (JsonProcessingException e) {
|
||||
@@ -180,22 +140,17 @@ public class RedisCacheService extends CacheService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateUserCategories(User user) {
|
||||
public void invalidateUserRootCategory(User... users) {
|
||||
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);
|
||||
Pipeline pipe = jedis.pipelined();
|
||||
if (users != null) {
|
||||
for (User user : users) {
|
||||
String key = buildRedisUserRootCategoryKey(user);
|
||||
pipe.del(key);
|
||||
}
|
||||
}
|
||||
pipe.sync();
|
||||
} finally {
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
@@ -222,14 +177,10 @@ public class RedisCacheService extends CacheService {
|
||||
return "f:" + Models.getId(feed);
|
||||
}
|
||||
|
||||
private String buildRedisUserCategoriesKey(User user) {
|
||||
private String buildRedisUserRootCategoryKey(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user