From a70cf9770018a47c02e3574c7396ccd0799fdb1b Mon Sep 17 00:00:00 2001 From: Athou Date: Mon, 12 Aug 2024 21:27:21 +0200 Subject: [PATCH] remove redis as caching is no longer needed now --- .../src/pages/admin/MetricsPage.tsx | 3 +- commafeed-server/TODO.md | 1 - commafeed-server/pom.xml | 5 - .../com/commafeed/CommaFeedConfiguration.java | 54 ------ .../com/commafeed/CommaFeedProducers.java | 15 -- .../commafeed/backend/cache/CacheService.java | 39 ----- .../backend/cache/NoopCacheService.java | 54 ------ .../backend/cache/RedisCacheService.java | 154 ------------------ .../backend/feed/FeedRefreshUpdater.java | 45 +---- .../commafeed/backend/opml/OPMLImporter.java | 3 - .../backend/service/FeedEntryService.java | 6 - .../service/FeedSubscriptionService.java | 22 +-- .../frontend/resource/CategoryREST.java | 26 +-- .../commafeed/frontend/resource/FeedREST.java | 3 - .../backend/opml/OPMLImporterTest.java | 4 +- 15 files changed, 23 insertions(+), 411 deletions(-) delete mode 100644 commafeed-server/src/main/java/com/commafeed/backend/cache/CacheService.java delete mode 100644 commafeed-server/src/main/java/com/commafeed/backend/cache/NoopCacheService.java delete mode 100644 commafeed-server/src/main/java/com/commafeed/backend/cache/RedisCacheService.java diff --git a/commafeed-client/src/pages/admin/MetricsPage.tsx b/commafeed-client/src/pages/admin/MetricsPage.tsx index c0e1ef01f..d90e6227b 100644 --- a/commafeed-client/src/pages/admin/MetricsPage.tsx +++ b/commafeed-client/src/pages/admin/MetricsPage.tsx @@ -11,8 +11,7 @@ const shownMeters: Record = { "com.commafeed.backend.feed.FeedRefreshEngine.refill": "Feed queue refill rate", "com.commafeed.backend.feed.FeedRefreshWorker.feedFetched": "Feed fetching rate", "com.commafeed.backend.feed.FeedRefreshUpdater.feedUpdated": "Feed update rate", - "com.commafeed.backend.feed.FeedRefreshUpdater.entryCacheHit": "Entry cache hit rate", - "com.commafeed.backend.feed.FeedRefreshUpdater.entryCacheMiss": "Entry cache miss rate", + "com.commafeed.backend.feed.FeedRefreshUpdater.entryInserted": "Entries inserted", "com.commafeed.backend.service.db.DatabaseCleaningService.entriesDeleted": "Entries deleted", } diff --git a/commafeed-server/TODO.md b/commafeed-server/TODO.md index 700b5bccc..b314b87a0 100644 --- a/commafeed-server/TODO.md +++ b/commafeed-server/TODO.md @@ -3,7 +3,6 @@ TODO MVP: -- remove redis, not useful anymore - update readme - update docker readme - update release notes (+ mention h2 migration has been removed, upgrade to last 4.x is required) diff --git a/commafeed-server/pom.xml b/commafeed-server/pom.xml index 57b1bf31f..fbd54e207 100644 --- a/commafeed-server/pom.xml +++ b/commafeed-server/pom.xml @@ -349,11 +349,6 @@ passay 1.6.4 - - redis.clients - jedis - 5.1.4 - com.rometools diff --git a/commafeed-server/src/main/java/com/commafeed/CommaFeedConfiguration.java b/commafeed-server/src/main/java/com/commafeed/CommaFeedConfiguration.java index d1b923604..1b5c225a7 100644 --- a/commafeed-server/src/main/java/com/commafeed/CommaFeedConfiguration.java +++ b/commafeed-server/src/main/java/com/commafeed/CommaFeedConfiguration.java @@ -12,12 +12,6 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Positive; -import redis.clients.jedis.DefaultJedisClientConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisClientConfig; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; -import redis.clients.jedis.Protocol; /** * CommaFeed configuration @@ -92,11 +86,6 @@ public interface CommaFeedConfiguration { */ Websocket websocket(); - /** - * Redis settings to enable caching. This is only really useful on instances with a lot of users. - */ - Redis redis(); - interface FeedRefresh { /** * Amount of time CommaFeed will wait before refreshing the same feed. @@ -230,47 +219,4 @@ interface Websocket { Duration treeReloadInterval(); } - interface Redis { - - Optional host(); - - @WithDefault("" + Protocol.DEFAULT_PORT) - int port(); - - /** - * Username is only required when using Redis ACLs - */ - Optional username(); - - Optional password(); - - @WithDefault("" + Protocol.DEFAULT_TIMEOUT) - int timeout(); - - @WithDefault("" + Protocol.DEFAULT_DATABASE) - int database(); - - @WithDefault("500") - int maxTotal(); - - default JedisPool build() { - Optional host = host(); - if (host.isEmpty()) { - throw new IllegalStateException("Redis host is required"); - } - - JedisPoolConfig poolConfig = new JedisPoolConfig(); - poolConfig.setMaxTotal(maxTotal()); - - JedisClientConfig clientConfig = DefaultJedisClientConfig.builder() - .user(username().orElse(null)) - .password(password().orElse(null)) - .timeoutMillis(timeout()) - .database(database()) - .build(); - - return new JedisPool(poolConfig, new HostAndPort(host.get(), port()), clientConfig); - } - } - } diff --git a/commafeed-server/src/main/java/com/commafeed/CommaFeedProducers.java b/commafeed-server/src/main/java/com/commafeed/CommaFeedProducers.java index 63df69ddc..7ab502166 100644 --- a/commafeed-server/src/main/java/com/commafeed/CommaFeedProducers.java +++ b/commafeed-server/src/main/java/com/commafeed/CommaFeedProducers.java @@ -1,10 +1,6 @@ package com.commafeed; import com.codahale.metrics.MetricRegistry; -import com.commafeed.CommaFeedConfiguration.Redis; -import com.commafeed.backend.cache.CacheService; -import com.commafeed.backend.cache.NoopCacheService; -import com.commafeed.backend.cache.RedisCacheService; import jakarta.enterprise.inject.Produces; import jakarta.inject.Singleton; @@ -12,17 +8,6 @@ @Singleton public class CommaFeedProducers { - @Produces - @Singleton - public CacheService cacheService(CommaFeedConfiguration config) { - Redis redis = config.redis(); - if (redis.host().isEmpty()) { - return new NoopCacheService(); - } - - return new RedisCacheService(redis.build()); - } - @Produces @Singleton public MetricRegistry metricRegistry() { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/cache/CacheService.java b/commafeed-server/src/main/java/com/commafeed/backend/cache/CacheService.java deleted file mode 100644 index 106927ef0..000000000 --- a/commafeed-server/src/main/java/com/commafeed/backend/cache/CacheService.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.commafeed.backend.cache; - -import java.util.List; -import java.util.Set; - -import com.commafeed.backend.Digests; -import com.commafeed.backend.feed.parser.FeedParserResult.Entry; -import com.commafeed.backend.model.Feed; -import com.commafeed.backend.model.FeedSubscription; -import com.commafeed.backend.model.User; -import com.commafeed.frontend.model.Category; -import com.commafeed.frontend.model.UnreadCount; - -public abstract class CacheService { - - // feed entries for faster refresh - public abstract Set getLastEntries(Feed feed); - - public abstract void setLastEntries(Feed feed, List entries); - - public String buildUniqueEntryKey(Entry entry) { - return Digests.sha1Hex(entry.guid() + entry.url()); - } - - // user categories - public abstract Category getUserRootCategory(User user); - - public abstract void setUserRootCategory(User user, Category category); - - public abstract void invalidateUserRootCategory(User... users); - - // unread count - public abstract UnreadCount getUnreadCount(FeedSubscription sub); - - public abstract void setUnreadCount(FeedSubscription sub, UnreadCount count); - - public abstract void invalidateUnreadCount(FeedSubscription... subs); - -} diff --git a/commafeed-server/src/main/java/com/commafeed/backend/cache/NoopCacheService.java b/commafeed-server/src/main/java/com/commafeed/backend/cache/NoopCacheService.java deleted file mode 100644 index 4b6ed9a0b..000000000 --- a/commafeed-server/src/main/java/com/commafeed/backend/cache/NoopCacheService.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.commafeed.backend.cache; - -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import com.commafeed.backend.model.Feed; -import com.commafeed.backend.model.FeedSubscription; -import com.commafeed.backend.model.User; -import com.commafeed.frontend.model.Category; -import com.commafeed.frontend.model.UnreadCount; - -public class NoopCacheService extends CacheService { - - @Override - public Set getLastEntries(Feed feed) { - return Collections.emptySet(); - } - - @Override - public void setLastEntries(Feed feed, List entries) { - } - - @Override - public UnreadCount getUnreadCount(FeedSubscription sub) { - return null; - } - - @Override - public void setUnreadCount(FeedSubscription sub, UnreadCount count) { - - } - - @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) { - - } - -} diff --git a/commafeed-server/src/main/java/com/commafeed/backend/cache/RedisCacheService.java b/commafeed-server/src/main/java/com/commafeed/backend/cache/RedisCacheService.java deleted file mode 100644 index 2f1e29139..000000000 --- a/commafeed-server/src/main/java/com/commafeed/backend/cache/RedisCacheService.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.commafeed.backend.cache; - -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import com.commafeed.backend.model.Feed; -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.commafeed.frontend.model.UnreadCount; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.Pipeline; - -@Slf4j -@RequiredArgsConstructor -public class RedisCacheService extends CacheService { - - private static final ObjectMapper MAPPER = new ObjectMapper().registerModule(new JavaTimeModule()); - - private final JedisPool pool; - - @Override - public Set getLastEntries(Feed feed) { - try (Jedis jedis = pool.getResource()) { - String key = buildRedisEntryKey(feed); - return jedis.smembers(key); - } - } - - @Override - public void setLastEntries(Feed feed, List entries) { - try (Jedis jedis = pool.getResource()) { - String key = buildRedisEntryKey(feed); - - Pipeline pipe = jedis.pipelined(); - pipe.del(key); - for (String entry : entries) { - pipe.sadd(key, entry); - } - pipe.expire(key, (int) TimeUnit.DAYS.toSeconds(7)); - pipe.sync(); - } - } - - @Override - public Category getUserRootCategory(User user) { - Category cat = null; - try (Jedis jedis = pool.getResource()) { - String key = buildRedisUserRootCategoryKey(user); - String json = jedis.get(key); - if (json != null) { - cat = MAPPER.readValue(json, Category.class); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return cat; - } - - @Override - public void setUserRootCategory(User user, Category category) { - try (Jedis jedis = pool.getResource()) { - String key = buildRedisUserRootCategoryKey(user); - - Pipeline pipe = jedis.pipelined(); - pipe.del(key); - pipe.set(key, MAPPER.writeValueAsString(category)); - pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30)); - pipe.sync(); - } catch (JsonProcessingException e) { - log.error(e.getMessage(), e); - } - } - - @Override - public UnreadCount getUnreadCount(FeedSubscription sub) { - UnreadCount count = null; - try (Jedis jedis = pool.getResource()) { - String key = buildRedisUnreadCountKey(sub); - String json = jedis.get(key); - if (json != null) { - count = MAPPER.readValue(json, UnreadCount.class); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return count; - } - - @Override - public void setUnreadCount(FeedSubscription sub, UnreadCount count) { - try (Jedis jedis = pool.getResource()) { - String key = buildRedisUnreadCountKey(sub); - - Pipeline pipe = jedis.pipelined(); - pipe.del(key); - pipe.set(key, MAPPER.writeValueAsString(count)); - pipe.expire(key, (int) TimeUnit.MINUTES.toSeconds(30)); - pipe.sync(); - } catch (Exception e) { - log.error(e.getMessage(), e); - } - } - - @Override - public void invalidateUserRootCategory(User... users) { - try (Jedis jedis = pool.getResource()) { - Pipeline pipe = jedis.pipelined(); - if (users != null) { - for (User user : users) { - String key = buildRedisUserRootCategoryKey(user); - pipe.del(key); - } - } - pipe.sync(); - } - } - - @Override - public void invalidateUnreadCount(FeedSubscription... subs) { - try (Jedis jedis = pool.getResource()) { - Pipeline pipe = jedis.pipelined(); - if (subs != null) { - for (FeedSubscription sub : subs) { - String key = buildRedisUnreadCountKey(sub); - pipe.del(key); - } - } - pipe.sync(); - } - } - - private String buildRedisEntryKey(Feed feed) { - return "f:" + Models.getId(feed); - } - - private String buildRedisUserRootCategoryKey(User user) { - return "c:" + Models.getId(user); - } - - private String buildRedisUnreadCountKey(FeedSubscription sub) { - return "u:" + Models.getId(sub); - } - -} diff --git a/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java b/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java index b22379298..b5df83cc6 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/feed/FeedRefreshUpdater.java @@ -1,6 +1,5 @@ package com.commafeed.backend.feed; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -16,7 +15,6 @@ import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistry; import com.commafeed.backend.Digests; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedSubscriptionDAO; import com.commafeed.backend.dao.UnitOfWork; import com.commafeed.backend.feed.parser.FeedParserResult.Content; @@ -25,7 +23,6 @@ import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedSubscription; import com.commafeed.backend.model.Models; -import com.commafeed.backend.model.User; import com.commafeed.backend.service.FeedEntryService; import com.commafeed.backend.service.FeedService; import com.commafeed.frontend.ws.WebSocketMessageBuilder; @@ -47,29 +44,23 @@ public class FeedRefreshUpdater { private final FeedService feedService; private final FeedEntryService feedEntryService; private final FeedSubscriptionDAO feedSubscriptionDAO; - private final CacheService cache; private final WebSocketSessions webSocketSessions; private final Striped locks; - private final Meter entryCacheMiss; - private final Meter entryCacheHit; private final Meter feedUpdated; private final Meter entryInserted; public FeedRefreshUpdater(UnitOfWork unitOfWork, FeedService feedService, FeedEntryService feedEntryService, MetricRegistry metrics, - FeedSubscriptionDAO feedSubscriptionDAO, CacheService cache, WebSocketSessions webSocketSessions) { + FeedSubscriptionDAO feedSubscriptionDAO, WebSocketSessions webSocketSessions) { this.unitOfWork = unitOfWork; this.feedService = feedService; this.feedEntryService = feedEntryService; this.feedSubscriptionDAO = feedSubscriptionDAO; - this.cache = cache; this.webSocketSessions = webSocketSessions; locks = Striped.lazyWeakLock(100000); - entryCacheMiss = metrics.meter(MetricRegistry.name(getClass(), "entryCacheMiss")); - entryCacheHit = metrics.meter(MetricRegistry.name(getClass(), "entryCacheHit")); feedUpdated = metrics.meter(MetricRegistry.name(getClass(), "feedUpdated")); entryInserted = metrics.meter(MetricRegistry.name(getClass(), "entryInserted")); } @@ -139,39 +130,21 @@ public boolean update(Feed feed, List entries) { Map unreadCountBySubscription = new HashMap<>(); if (!entries.isEmpty()) { - Set lastEntries = cache.getLastEntries(feed); - List currentEntries = new ArrayList<>(); - List subscriptions = null; for (Entry entry : entries) { - String cacheKey = cache.buildUniqueEntryKey(entry); - if (!lastEntries.contains(cacheKey)) { - log.debug("cache miss for {}", entry.url()); - if (subscriptions == null) { - subscriptions = unitOfWork.call(() -> feedSubscriptionDAO.findByFeed(feed)); - } - AddEntryResult addEntryResult = addEntry(feed, entry, subscriptions); - processed &= addEntryResult.processed; - inserted += addEntryResult.inserted ? 1 : 0; - addEntryResult.subscriptionsForWhichEntryIsUnread.forEach(sub -> unreadCountBySubscription.merge(sub, 1L, Long::sum)); - - entryCacheMiss.mark(); - } else { - log.debug("cache hit for {}", entry.url()); - entryCacheHit.mark(); + if (subscriptions == null) { + subscriptions = unitOfWork.call(() -> feedSubscriptionDAO.findByFeed(feed)); } - - currentEntries.add(cacheKey); + AddEntryResult addEntryResult = addEntry(feed, entry, subscriptions); + processed &= addEntryResult.processed; + inserted += addEntryResult.inserted ? 1 : 0; + addEntryResult.subscriptionsForWhichEntryIsUnread.forEach(sub -> unreadCountBySubscription.merge(sub, 1L, Long::sum)); } - cache.setLastEntries(feed, currentEntries); - if (subscriptions == null) { + if (inserted == 0) { feed.setMessage("No new entries found"); } else if (inserted > 0) { - log.debug("inserted {} entries for feed {}", inserted, feed.getId()); - List users = subscriptions.stream().map(FeedSubscription::getUser).toList(); - cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0])); - cache.invalidateUserRootCategory(users.toArray(new User[0])); + feed.setMessage("Found %s new entries".formatted(inserted)); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java b/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java index f28c5247f..4465025ca 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/opml/OPMLImporter.java @@ -6,7 +6,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.feed.FeedUtils; import com.commafeed.backend.model.FeedCategory; @@ -28,7 +27,6 @@ public class OPMLImporter { private final FeedCategoryDAO feedCategoryDAO; private final FeedSubscriptionService feedSubscriptionService; - private final CacheService cache; public void importOpml(User user, String xml) throws IllegalArgumentException, FeedException { xml = xml.substring(xml.indexOf('<')); @@ -79,6 +77,5 @@ private void handleOutline(User user, Outline outline, FeedCategory parent, int log.error("error while importing {}: {}", outline.getXmlUrl(), e.getMessage()); } } - cache.invalidateUserRootCategory(user); } } diff --git a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedEntryService.java b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedEntryService.java index 7b789042e..505245a68 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedEntryService.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedEntryService.java @@ -4,7 +4,6 @@ import java.util.List; import com.commafeed.backend.Digests; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedEntryDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedSubscriptionDAO; @@ -32,7 +31,6 @@ public class FeedEntryService { private final FeedEntryStatusDAO feedEntryStatusDAO; private final FeedEntryContentService feedEntryContentService; private final FeedEntryFilteringService feedEntryFilteringService; - private final CacheService cache; public FeedEntry find(Feed feed, Entry entry) { String guidHash = Digests.sha1Hex(entry.guid()); @@ -85,8 +83,6 @@ public void markEntry(User user, Long entryId, boolean read) { if (status.isMarkable()) { status.setRead(read); feedEntryStatusDAO.saveOrUpdate(status); - cache.invalidateUnreadCount(sub); - cache.invalidateUserRootCategory(user); } } @@ -112,8 +108,6 @@ public void markSubscriptionEntries(User user, List subscripti List statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, keywords, null, -1, -1, null, false, null, null, null); markList(statuses, olderThan, insertedBefore); - cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0])); - cache.invalidateUserRootCategory(user); } public void markStarredEntries(User user, Instant olderThan, Instant insertedBefore) { diff --git a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java index 5f48a7c19..45d6674fb 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/service/FeedSubscriptionService.java @@ -8,7 +8,6 @@ import org.apache.commons.lang3.StringUtils; import com.commafeed.CommaFeedConfiguration; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedSubscriptionDAO; @@ -17,7 +16,6 @@ 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.UnreadCount; @@ -33,17 +31,15 @@ public class FeedSubscriptionService { private final FeedSubscriptionDAO feedSubscriptionDAO; private final FeedService feedService; private final FeedRefreshEngine feedRefreshEngine; - private final CacheService cache; private final CommaFeedConfiguration config; public FeedSubscriptionService(FeedDAO feedDAO, FeedEntryStatusDAO feedEntryStatusDAO, FeedSubscriptionDAO feedSubscriptionDAO, - FeedService feedService, FeedRefreshEngine feedRefreshEngine, CacheService cache, CommaFeedConfiguration config) { + FeedService feedService, FeedRefreshEngine feedRefreshEngine, CommaFeedConfiguration config) { this.feedDAO = feedDAO; this.feedEntryStatusDAO = feedEntryStatusDAO; this.feedSubscriptionDAO = feedSubscriptionDAO; this.feedService = feedService; this.feedRefreshEngine = feedRefreshEngine; - this.cache = cache; this.config = config; // automatically refresh feeds after they are subscribed to @@ -95,7 +91,6 @@ public long subscribe(User user, String url, String title, FeedCategory category sub.setTitle(FeedUtils.truncate(title, 128)); feedSubscriptionDAO.saveOrUpdate(sub); - cache.invalidateUserRootCategory(user); return sub.getId(); } @@ -103,7 +98,6 @@ public boolean unsubscribe(User user, Long subId) { FeedSubscription sub = feedSubscriptionDAO.findById(user, subId); if (sub != null) { feedSubscriptionDAO.delete(sub); - cache.invalidateUserRootCategory(user); return true; } else { return false; @@ -130,17 +124,9 @@ public void refreshAllUpForRefresh(User user) { } public Map getUnreadCount(User user) { - return feedSubscriptionDAO.findAll(user).stream().collect(Collectors.toMap(FeedSubscription::getId, this::getUnreadCount)); - } - - 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(sub); - cache.setUnreadCount(sub, count); - } - return count; + return feedSubscriptionDAO.findAll(user) + .stream() + .collect(Collectors.toMap(FeedSubscription::getId, feedEntryStatusDAO::getUnreadCount)); } @SuppressWarnings("serial") diff --git a/commafeed-server/src/main/java/com/commafeed/frontend/resource/CategoryREST.java b/commafeed-server/src/main/java/com/commafeed/frontend/resource/CategoryREST.java index 3a6fd3623..668db51c5 100644 --- a/commafeed-server/src/main/java/com/commafeed/frontend/resource/CategoryREST.java +++ b/commafeed-server/src/main/java/com/commafeed/frontend/resource/CategoryREST.java @@ -14,7 +14,6 @@ import org.apache.commons.lang3.StringUtils; import com.commafeed.CommaFeedConfiguration; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedSubscriptionDAO; @@ -89,7 +88,6 @@ public class CategoryREST { private final FeedSubscriptionDAO feedSubscriptionDAO; private final FeedEntryService feedEntryService; private final FeedSubscriptionService feedSubscriptionService; - private final CacheService cache; private final CommaFeedConfiguration config; @Path("/entries") @@ -291,7 +289,6 @@ public Response addCategory(@Valid @Parameter(required = true) AddCategoryReques cat.setParent(parent); } feedCategoryDAO.saveOrUpdate(cat); - cache.invalidateUserRootCategory(user); return Response.ok(cat.getId()).build(); } @@ -321,7 +318,6 @@ public Response deleteCategory(@Parameter(required = true) IDRequest req) { feedCategoryDAO.saveOrUpdate(categories); feedCategoryDAO.delete(cat); - cache.invalidateUserRootCategory(user); return Response.ok().build(); } else { return Response.status(Status.NOT_FOUND).build(); @@ -374,7 +370,6 @@ public Response modifyCategory(@Valid @Parameter(required = true) CategoryModifi } feedCategoryDAO.saveOrUpdate(category); - cache.invalidateUserRootCategory(user); return Response.ok().build(); } @@ -393,7 +388,6 @@ public Response collapseCategory(@Parameter(required = true) CollapseRequest req } category.setCollapsed(req.isCollapse()); feedCategoryDAO.saveOrUpdate(category); - cache.invalidateUserRootCategory(user); return Response.ok().build(); } @@ -418,18 +412,14 @@ public Response getUnreadCount() { responses = { @ApiResponse(content = @Content(schema = @Schema(implementation = Category.class))) }) public Response getRootCategory() { User user = authenticationContext.getCurrentUser(); - Category root = cache.getUserRootCategory(user); - if (root == null) { - log.debug("tree cache miss for {}", user.getId()); - List categories = feedCategoryDAO.findAll(user); - List subscriptions = feedSubscriptionDAO.findAll(user); - Map unreadCount = feedSubscriptionService.getUnreadCount(user); - - root = buildCategory(null, categories, subscriptions, unreadCount); - root.setId("all"); - root.setName("All"); - cache.setUserRootCategory(user, root); - } + + List categories = feedCategoryDAO.findAll(user); + List subscriptions = feedSubscriptionDAO.findAll(user); + Map unreadCount = feedSubscriptionService.getUnreadCount(user); + + Category root = buildCategory(null, categories, subscriptions, unreadCount); + root.setId("all"); + root.setName("All"); return Response.ok(root).build(); } diff --git a/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java b/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java index 685867e5d..33543b78b 100644 --- a/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java +++ b/commafeed-server/src/main/java/com/commafeed/frontend/resource/FeedREST.java @@ -17,7 +17,6 @@ import com.commafeed.CommaFeedApplication; import com.commafeed.CommaFeedConfiguration; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.dao.FeedEntryStatusDAO; import com.commafeed.backend.dao.FeedSubscriptionDAO; @@ -114,7 +113,6 @@ public class FeedREST { private final FeedRefreshEngine feedRefreshEngine; private final OPMLImporter opmlImporter; private final OPMLExporter opmlExporter; - private final CacheService cache; private final CommaFeedConfiguration config; private static FeedEntry initTestEntry() { @@ -492,7 +490,6 @@ public Response modifyFeed(@Valid @Parameter(description = "subscription id", re } else { feedSubscriptionDAO.saveOrUpdate(subscription); } - cache.invalidateUserRootCategory(user); return Response.ok().build(); } diff --git a/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java b/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java index ae89f32ec..08cd6f90f 100644 --- a/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java +++ b/commafeed-server/src/test/java/com/commafeed/backend/opml/OPMLImporterTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import com.commafeed.backend.cache.CacheService; import com.commafeed.backend.dao.FeedCategoryDAO; import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.User; @@ -39,12 +38,11 @@ void testOpmlNoVersion() throws IOException, IllegalArgumentException, FeedExcep private void testOpmlVersion(String fileName) throws IOException, IllegalArgumentException, FeedException { FeedCategoryDAO feedCategoryDAO = Mockito.mock(FeedCategoryDAO.class); FeedSubscriptionService feedSubscriptionService = Mockito.mock(FeedSubscriptionService.class); - CacheService cacheService = Mockito.mock(CacheService.class); User user = Mockito.mock(User.class); String xml = IOUtils.toString(getClass().getResourceAsStream(fileName), StandardCharsets.UTF_8); - OPMLImporter importer = new OPMLImporter(feedCategoryDAO, feedSubscriptionService, cacheService); + OPMLImporter importer = new OPMLImporter(feedCategoryDAO, feedSubscriptionService); importer.importOpml(user, xml); Mockito.verify(feedSubscriptionService)