Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public static class CacheKeys
/// </summary>
public const string SermonsPattern = "thrive:sermons:*";

/// <summary>
/// Sitemap data containing all series and message IDs
/// </summary>
public const string SitemapData = "thrive:sermons:sitemap";

// ============================================
// Configuration Cache Keys
// ============================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace ThriveChurchOfficialAPI.Core
{
/// <summary>
/// Response containing minimal sermon data optimized for sitemap generation
/// </summary>
public class SitemapDataResponse
{
/// <summary>
/// C'tor
/// </summary>
public SitemapDataResponse()
{
Series = new List<SitemapSeriesData>();
}

/// <summary>
/// Collection of sermon series with their messages
/// </summary>
public List<SitemapSeriesData> Series { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace ThriveChurchOfficialAPI.Core
{
/// <summary>
/// Minimal message data for sitemap generation
/// </summary>
public class SitemapMessageData
{
/// <summary>
/// The unique identifier of the message
/// </summary>
public string Id { get; set; }

/// <summary>
/// The date this message was given
/// </summary>
public DateTime? Date { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;

namespace ThriveChurchOfficialAPI.Core
{
/// <summary>
/// Minimal series data for sitemap generation
/// </summary>
public class SitemapSeriesData
{
/// <summary>
/// C'tor
/// </summary>
public SitemapSeriesData()
{
Id = null;
Messages = new List<SitemapMessageData>();
}

/// <summary>
/// The unique identifier of the sermon series
/// </summary>
public string Id { get; set; }

/// <summary>
/// The last time this series was updated
/// </summary>
public DateTime LastUpdated { get; set; }

/// <summary>
/// Collection of messages in this series
/// </summary>
public List<SitemapMessageData> Messages { get; set; }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,11 @@ public interface ISermonsService
/// <param name="request"></param>
/// <returns></returns>
Task<PodcastMessage> UpdatePodcastMessage(string messageId, PodcastMessageRequest request);

/// <summary>
/// Gets minimal sermon data for sitemap generation
/// </summary>
/// <returns>Series IDs, message IDs, and dates for sitemap URLs</returns>
Task<SystemResponse<SitemapDataResponse>> GetSitemapData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1872,5 +1872,61 @@ public Task<PodcastMessage> UpdatePodcastMessage(string messageId, PodcastMessag
{
return _podcastMessagesRepository.UpdatePodcastMessageById(messageId, request);
}

/// <summary>
/// Gets minimal sermon data for sitemap generation
/// </summary>
/// <returns>Series IDs, message IDs, and dates for sitemap URLs</returns>
public async Task<SystemResponse<SitemapDataResponse>> GetSitemapData()
{
// Check cache first
var cacheKey = CacheKeys.SitemapData;
var cachedResponse = _cache.ReadFromCache<SitemapDataResponse>(cacheKey);
if (cachedResponse != null)
{
return new SystemResponse<SitemapDataResponse>(cachedResponse, "Success!");
}

// Use existing cached service method to get all series summaries
var allSermonsResponse = await GetAllSermons(highResImg: false);
if (allSermonsResponse.HasErrors)
{
return new SystemResponse<SitemapDataResponse>(true, allSermonsResponse.ErrorMessage);
}

var allSeries = allSermonsResponse.Result.Summaries;
if (allSeries == null)
{
return new SystemResponse<SitemapDataResponse>(true, "Failed to retrieve sermon series data");
}

// For each series, get the full series data (with messages) from cache
// GetSeriesForId already uses caching at thrive:sermons:series:{seriesId}
var seriesDataTasks = allSeries.Select(s => GetSeriesForId(s.Id)).ToList();
await Task.WhenAll(seriesDataTasks);

// Build minimal response from cached data
var response = new SitemapDataResponse
{
Series = seriesDataTasks
.Where(t => !t.Result.HasErrors && t.Result.Result != null)
.Select(t => t.Result.Result)
.Select(series => new SitemapSeriesData
{
Id = series.Id,
LastUpdated = series.LastUpdated ?? DateTime.MinValue,
Messages = series.Messages?.Select(msg => new SitemapMessageData
{
Id = msg.MessageId,
Date = msg.Date
}).ToList() ?? new List<SitemapMessageData>()
}).ToList()
};

// Cache for 2 hours (matches sitemap ISR revalidation)
_cache.InsertIntoCache(cacheKey, response, TimeSpan.FromHours(2));

return new SystemResponse<SitemapDataResponse>(response, "Success!");
}
}
}
Loading
Loading