mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
prevent duplicate entries for push infos
This commit is contained in:
@@ -16,6 +16,7 @@ import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedPushInfo;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.commafeed.backend.services.FeedPushInfoService;
|
||||
import com.sun.syndication.io.FeedException;
|
||||
|
||||
public class FeedRefreshWorker {
|
||||
@@ -35,6 +36,9 @@ public class FeedRefreshWorker {
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@Inject
|
||||
FeedPushInfoService feedPushInfoService;
|
||||
|
||||
public void start(MutableBoolean running, String threadName) {
|
||||
log.info("{} starting", threadName);
|
||||
|
||||
@@ -132,7 +136,7 @@ public class FeedRefreshWorker {
|
||||
log.debug("feed {} has pubsub info: {}", feed.getUrl(), topic);
|
||||
FeedPushInfo info = feed.getPushInfo();
|
||||
if (info == null) {
|
||||
info = new FeedPushInfo();
|
||||
info = feedPushInfoService.findOrCreate(feed, hub, topic);
|
||||
}
|
||||
if (!StringUtils.equals(hub, info.getHub())
|
||||
|| !StringUtils.equals(topic, info.getTopic())) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Lock;
|
||||
import javax.ejb.LockType;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.commafeed.backend.dao.FeedPushInfoDAO;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedPushInfo;
|
||||
import com.commafeed.backend.model.FeedPushInfo_;
|
||||
|
||||
@Singleton
|
||||
public class FeedPushInfoService {
|
||||
|
||||
@Inject
|
||||
FeedPushInfoDAO feedPushInfoDAO;
|
||||
|
||||
@Lock(LockType.WRITE)
|
||||
public FeedPushInfo findOrCreate(Feed feed, String hub, String topic) {
|
||||
FeedPushInfo info = null;
|
||||
|
||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByField(
|
||||
FeedPushInfo_.feed, feed);
|
||||
if (infos.isEmpty()) {
|
||||
info = new FeedPushInfo();
|
||||
info.setFeed(feed);
|
||||
info.setHub(hub);
|
||||
info.setTopic(topic);
|
||||
info.setActive(false);
|
||||
feedPushInfoDAO.save(info);
|
||||
} else {
|
||||
info = infos.get(0);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user