From 34557a78deb5c95aa096cbc2851ababb3342691b Mon Sep 17 00:00:00 2001 From: Mark Downie Date: Fri, 21 Jan 2022 21:57:40 -0500 Subject: [PATCH] If the category does not exist do not return any data. This prevents injecting user data in the rss category title if it does not exist. Also prevents caching of data unnecessarily. --- .../DasBlog.Web.UI/Controllers/FeedController.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/DasBlog.Web.UI/Controllers/FeedController.cs b/source/DasBlog.Web.UI/Controllers/FeedController.cs index e13ab500f..3041a3b44 100644 --- a/source/DasBlog.Web.UI/Controllers/FeedController.cs +++ b/source/DasBlog.Web.UI/Controllers/FeedController.cs @@ -41,8 +41,6 @@ public IActionResult Rss() memoryCache.Set(CACHEKEY_RSS, rss, SiteCacheSettings()); } - logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "RSS request")); - return Ok(rss); } @@ -50,15 +48,20 @@ public IActionResult Rss() [HttpGet("feed/rss/{category}"), HttpHead("feed/rss/{category}")] public IActionResult RssByCategory(string category) { - if (!memoryCache.TryGetValue(CACHEKEY_RSS + "_" + category, out RssRoot rss)) { rss = subscriptionManager.GetRssCategory(category); - memoryCache.Set(CACHEKEY_RSS + "_" + category, rss, SiteCacheSettings()); + if (rss.Channels[0]?.Items?.Count > 0) + { + memoryCache.Set(CACHEKEY_RSS + "_" + category, rss, SiteCacheSettings()); + } } - logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "RSS category request: '{0}'", category)); + if(rss.Channels[0]?.Items?.Count == 0) + { + return NoContent(); + } return Ok(rss); } @@ -106,8 +109,6 @@ public async Task BloggerPost() logger.LogError(new EventDataItem(EventCodes.RSS, null, "FeedController.BloggerPost Error: {0}", ex.Message)); } - logger.LogInformation(new EventDataItem(EventCodes.RSS, null, "FeedController.BloggerPost successfully submitted")); - BreakSiteCache(); return Content(blogger);