invalidate cache once per feed instead of once per entry

This commit is contained in:
Athou
2013-07-31 16:03:52 +02:00
parent a37925396a
commit 8f85637bb8
2 changed files with 17 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -120,9 +121,19 @@ public class FeedRefreshUpdater {
log.debug("cache hit for {}", entry.getUrl()); log.debug("cache hit for {}", entry.getUrl());
metricsBean.entryCacheHit(); metricsBean.entryCacheHit();
} }
currentEntries.add(cacheKey); currentEntries.add(cacheKey);
} }
cache.setLastEntries(feed, currentEntries); cache.setLastEntries(feed, currentEntries);
if (CollectionUtils.isNotEmpty(subscriptions)) {
List<User> users = Lists.newArrayList();
for (FeedSubscription sub : subscriptions) {
users.add(sub.getUser());
}
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
cache.invalidateUserRootCategory(users.toArray(new User[0]));
}
} }
if (applicationSettingsService.get().isPubsubhubbub()) { if (applicationSettingsService.get().isPubsubhubbub()) {
@@ -163,14 +174,10 @@ public class FeedRefreshUpdater {
locked1 = lock1.tryLock(1, TimeUnit.MINUTES); locked1 = lock1.tryLock(1, TimeUnit.MINUTES);
locked2 = lock2.tryLock(1, TimeUnit.MINUTES); locked2 = lock2.tryLock(1, TimeUnit.MINUTES);
if (locked1 && locked2) { if (locked1 && locked2) {
feedUpdateService.updateEntry(feed, entry); boolean inserted = feedUpdateService.addEntry(feed, entry);
List<User> users = Lists.newArrayList(); if (inserted) {
for (FeedSubscription sub : subscriptions) { metricsBean.entryInserted();
users.add(sub.getUser());
} }
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
cache.invalidateUserRootCategory(users.toArray(new User[0]));
metricsBean.entryInserted();
success = true; success = true;
} else { } else {
log.error("lock timeout for " + feed.getUrl() + " - " + key1); log.error("lock timeout for " + feed.getUrl() + " - " + key1);

View File

@@ -24,11 +24,11 @@ public class FeedUpdateService {
/** /**
* this is NOT thread-safe * this is NOT thread-safe
*/ */
public void updateEntry(Feed feed, FeedEntry entry) { public boolean addEntry(Feed feed, FeedEntry entry) {
Long existing = feedEntryDAO.findExisting(entry.getGuid(), feed.getId()); Long existing = feedEntryDAO.findExisting(entry.getGuid(), feed.getId());
if (existing != null) { if (existing != null) {
return; return false;
} }
FeedEntryContent content = feedEntryContentService.findOrCreate(entry.getContent(), feed.getLink()); FeedEntryContent content = feedEntryContentService.findOrCreate(entry.getContent(), feed.getLink());
@@ -38,5 +38,6 @@ public class FeedUpdateService {
entry.setFeed(feed); entry.setFeed(feed);
feedEntryDAO.saveOrUpdate(entry); feedEntryDAO.saveOrUpdate(entry);
return true;
} }
} }