commit a12a1fe1121807ac931c21d75a8c6cda28e5a719 parent 83d48815695df266c78b7a18db1f910c295939d9 Author: WimDupont <WimDupont@users.noreply.gitlab.com> Date: Fri, 5 Nov 2021 17:17:47 +0100 Reduces times rssfeed channel gets generated Former-commit-id: 5a64ad9e86e4b9c0d8cc673f417b2867db4ac316 Diffstat:
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/wimdupont/personalweb/controller/FeedController.java b/src/main/java/com/wimdupont/personalweb/controller/FeedController.java @@ -16,6 +16,6 @@ public class FeedController { @GetMapping(path = "/rss.xml") @SuppressWarnings("unused") public Channel getRss(Model model) { - return rssFeed.generate(); + return rssFeed.getChannel(); } } diff --git a/src/main/java/com/wimdupont/personalweb/service/BlogArticleGenerator.java b/src/main/java/com/wimdupont/personalweb/service/BlogArticleGenerator.java @@ -20,6 +20,7 @@ import java.nio.file.Paths; public class BlogArticleGenerator { private final AdocConverter adocConverter; + private final RssFeedGenerator rssFeedGenerator; @Scheduled(cron = "0 0 0 * * *") public void generate() { @@ -40,5 +41,6 @@ public class BlogArticleGenerator { } } } + rssFeedGenerator.generate(); } } diff --git a/src/main/java/com/wimdupont/personalweb/service/RssFeedGenerator.java b/src/main/java/com/wimdupont/personalweb/service/RssFeedGenerator.java @@ -5,11 +5,10 @@ import com.rometools.rome.feed.rss.Content; import com.rometools.rome.feed.rss.Guid; import com.rometools.rome.feed.rss.Item; import com.wimdupont.personalweb.util.Constants; -import lombok.RequiredArgsConstructor; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.transaction.Transactional; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -22,11 +21,12 @@ import java.util.List; @Slf4j @Service -@Transactional -@RequiredArgsConstructor public class RssFeedGenerator { - public Channel generate() { + @Getter + private Channel channel; + + public void generate() { Channel channel = new Channel(); channel.setFeedType("rss_2.0"); @@ -38,7 +38,7 @@ public class RssFeedGenerator { channel.setPubDate(new Date()); channel.setItems(getItems()); - return channel; + this.channel = channel; } private List<Item> getItems() {