do the heavy work outside of the locked method

This commit is contained in:
Athou
2013-05-21 17:00:37 +02:00
parent f93ecd8607
commit e1b8fa4e76
2 changed files with 20 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import com.commafeed.backend.dao.FeedDAO;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.FeedPushInfo;
import com.commafeed.backend.pubsubhubbub.SubscriptionHandler;
import com.commafeed.backend.services.ApplicationSettingsService;
@@ -39,6 +40,9 @@ public class FeedRefreshUpdater {
@Asynchronous
public void updateEntries(Feed feed, Collection<FeedEntry> entries) {
if (CollectionUtils.isNotEmpty(entries)) {
for (FeedEntry entry : entries) {
handleEntry(feed, entry);
}
feedUpdateService.updateEntries(feed, entries);
}
feedDAO.update(feed);
@@ -47,6 +51,22 @@ public class FeedRefreshUpdater {
}
}
private void handleEntry(Feed feed, FeedEntry entry) {
String baseUri = feed.getLink();
FeedEntryContent content = entry.getContent();
content.setContent(FeedUtils.handleContent(content.getContent(),
baseUri));
String title = FeedUtils.handleContent(content.getTitle(), baseUri);
if (title != null) {
content.setTitle(title.substring(0, Math.min(2048, title.length())));
}
String author = entry.getAuthor();
if (author != null) {
entry.setAuthor(author.substring(0, Math.min(128, author.length())));
}
}
private void handlePubSub(final Feed feed) {
FeedPushInfo info = feed.getPushInfo();
if (info != null && info.isActive() == false) {

View File

@@ -19,10 +19,8 @@ import com.commafeed.backend.MetricsBean;
import com.commafeed.backend.dao.FeedEntryDAO;
import com.commafeed.backend.dao.FeedEntryStatusDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.feeds.FeedUtils;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedSubscription;
import com.google.common.collect.Lists;
@@ -57,23 +55,6 @@ public class FeedUpdateService {
FeedEntry foundEntry = findEntry(existingEntries, entry);
if (foundEntry == null) {
String baseUri = feed.getLink();
FeedEntryContent content = entry.getContent();
content.setContent(FeedUtils.handleContent(
content.getContent(), baseUri));
String title = FeedUtils.handleContent(content.getTitle(),
baseUri);
if (title != null) {
content.setTitle(title.substring(0,
Math.min(2048, title.length())));
}
String author = entry.getAuthor();
if (author != null) {
entry.setAuthor(author.substring(0,
Math.min(128, author.length())));
}
entry.setInserted(Calendar.getInstance().getTime());
entry.getFeeds().add(feed);
entryUpdateList.add(entry);