return to async beans, jms is too much overhead atm

This commit is contained in:
Athou
2013-04-25 17:26:07 +02:00
parent 84f9b4e10e
commit 2af55553a2
4 changed files with 55 additions and 153 deletions

View File

@@ -5,9 +5,13 @@ import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
@@ -24,6 +28,7 @@ import com.commafeed.backend.model.FeedSubscription;
import com.google.common.collect.Lists;
@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class FeedUpdateService {
@Inject
@@ -38,59 +43,63 @@ public class FeedUpdateService {
@Inject
FeedEntryStatusDAO feedEntryStatusDAO;
@Asynchronous
public void updateEntries(Feed feed, Collection<FeedEntry> entries) {
List<FeedEntry> existingEntries = getExistingEntries(entries);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findByFeed(feed);
if (CollectionUtils.isNotEmpty(entries)) {
List<FeedEntry> existingEntries = getExistingEntries(entries);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findByFeed(feed);
List<FeedEntry> entryUpdateList = Lists.newArrayList();
List<FeedEntryStatus> statusUpdateList = Lists.newArrayList();
for (FeedEntry entry : entries) {
List<FeedEntry> entryUpdateList = Lists.newArrayList();
List<FeedEntryStatus> statusUpdateList = Lists.newArrayList();
for (FeedEntry entry : entries) {
FeedEntry foundEntry = findEntry(existingEntries, entry);
FeedEntry foundEntry = findEntry(existingEntries, entry);
if (foundEntry == null) {
FeedEntryContent content = entry.getContent();
if (foundEntry == null) {
FeedEntryContent content = entry.getContent();
content.setContent(FeedUtils.handleContent(content.getContent()));
String title = FeedUtils.handleContent(content.getTitle());
if (title != null) {
content.setTitle(title.substring(0,
Math.min(2048, title.length())));
}
content.setContent(FeedUtils.handleContent(content
.getContent()));
String title = FeedUtils.handleContent(content.getTitle());
if (title != null) {
content.setTitle(title.substring(0,
Math.min(2048, title.length())));
}
entry.setInserted(Calendar.getInstance().getTime());
entry.getFeeds().add(feed);
entryUpdateList.add(entry);
} else {
boolean foundFeed = false;
for (Feed existingFeed : foundEntry.getFeeds()) {
if (ObjectUtils.equals(existingFeed.getId(), feed.getId())) {
foundFeed = true;
break;
entry.setInserted(Calendar.getInstance().getTime());
entry.getFeeds().add(feed);
entryUpdateList.add(entry);
} else {
boolean foundFeed = false;
for (Feed existingFeed : foundEntry.getFeeds()) {
if (ObjectUtils.equals(existingFeed.getId(),
feed.getId())) {
foundFeed = true;
break;
}
}
if (!foundFeed) {
foundEntry.getFeeds().add(feed);
entryUpdateList.add(entry);
}
}
if (!foundFeed) {
foundEntry.getFeeds().add(feed);
entryUpdateList.add(entry);
}
for (FeedEntry entry : entryUpdateList) {
for (FeedSubscription sub : subscriptions) {
FeedEntryStatus status = new FeedEntryStatus();
status.setEntry(entry);
status.setSubscription(sub);
statusUpdateList.add(status);
}
}
}
for (FeedEntry entry : entryUpdateList) {
for (FeedSubscription sub : subscriptions) {
FeedEntryStatus status = new FeedEntryStatus();
status.setEntry(entry);
status.setSubscription(sub);
statusUpdateList.add(status);
}
}
feedEntryDAO.saveOrUpdate(entryUpdateList);
feedEntryStatusDAO.saveOrUpdate(statusUpdateList);
}
feedDAO.update(feed);
feedEntryDAO.saveOrUpdate(entryUpdateList);
feedEntryStatusDAO.saveOrUpdate(statusUpdateList);
}
private FeedEntry findEntry(List<FeedEntry> existingEntries, FeedEntry entry) {