From dd991a4eee7d46c9ddd78e781d3a3cd9325e8538 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:05:53 +0100 Subject: [PATCH 1/6] Add logging to sessionize service update --- .../SessionizeService.cs | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs index 3f0a9ee..84715f6 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs @@ -1,33 +1,45 @@ -using Microsoft.EntityFrameworkCore; +using System.Net.Http.Json; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using PocketDDD.Server.DB; using PocketDDD.Server.Model.DBModel; using PocketDDD.Server.Model.Sessionize; -using System.Net.Http.Json; +using Session = PocketDDD.Server.Model.DBModel.Session; namespace PocketDDD.Server.Services; public class SessionizeService { - private readonly HttpClient httpClient; private readonly PocketDDDContext dbContext; + private readonly HttpClient httpClient; - public SessionizeService(HttpClient httpClient, PocketDDDContext dbContext) + public SessionizeService(HttpClient httpClient, PocketDDDContext dbContext, ILogger logger) { + Logger = logger; this.httpClient = httpClient; this.dbContext = dbContext; httpClient.BaseAddress = new Uri("https://sessionize.com/api/v2/"); } + private ILogger Logger { get; } + public async Task UpdateFromSessionize() { - var dbEvent = await dbContext.EventDetail.SingleAsync(x => x.Id == 1); + Logger.LogInformation("Looking for event detail in database"); + var dbEvent = await dbContext.EventDetail.SingleAsync(x => x.Id == 1); var sessionizeEventId = dbEvent.SessionizeId; + + Logger.LogInformation("About to get data from Sessionize API"); + var sessionizeEvent = await httpClient.GetFromJsonAsync($"{sessionizeEventId}/view/All"); if (sessionizeEvent is null) throw new ArgumentNullException(nameof(sessionizeEvent)); + Logger.LogInformation("Information retrieved from Sessionize API"); + Logger.LogInformation("Looking for changes to rooms"); + var dbTracks = await dbContext.Tracks.ToListAsync(); foreach (var item in sessionizeEvent.rooms) { @@ -46,8 +58,17 @@ public async Task UpdateFromSessionize() dbTrack.Name = $"Track {item.sort}"; } - await dbContext.SaveChangesAsync(); - + if (dbContext.ChangeTracker.HasChanges()) + { + Logger.LogInformation("Updating db with changes to rooms"); + await dbContext.SaveChangesAsync(); + } + else + { + Logger.LogInformation("No changes to rooms were detected"); + } + + Logger.LogInformation("Looking for changes to time slots and breaks"); var dbTimeSlots = await dbContext.TimeSlots.ToListAsync(); var sessionizeTimeSlots = sessionizeEvent.sessions @@ -71,10 +92,18 @@ public async Task UpdateFromSessionize() dbContext.TimeSlots.Add(dbTimeSlot); } } + if (dbContext.ChangeTracker.HasChanges()) + { + Logger.LogInformation("Updating db with changes to time slots and breaks"); + await dbContext.SaveChangesAsync(); + } + else + { + Logger.LogInformation("No changes to time slots or breaks were detected"); + } - await dbContext.SaveChangesAsync(); - - + Logger.LogInformation("Looking for changes to sessions"); + var dbSessions = await dbContext.Sessions.ToListAsync(); var speakers = sessionizeEvent.speakers; dbTracks = await dbContext.Tracks.ToListAsync(); @@ -89,7 +118,7 @@ public async Task UpdateFromSessionize() var dbSession = dbSessions.SingleOrDefault(x => x.SessionizeId == sessionizeId); if (dbSession == null) { - dbSession = new Model.DBModel.Session + dbSession = new Session { SessionizeId = sessionizeId, EventDetail = dbEvent, @@ -105,8 +134,15 @@ public async Task UpdateFromSessionize() dbSession.Track = dbTracks.Single(x => x.SessionizeId == item.roomId); dbSession.TimeSlot = GetTimeSlot(dbTimeSlots, item.startsAt, item.endsAt); } - - await dbContext.SaveChangesAsync(); + if (dbContext.ChangeTracker.HasChanges()) + { + Logger.LogInformation("Updating db with changes to sessions"); + await dbContext.SaveChangesAsync(); + } + else + { + Logger.LogInformation("No changes to sessions were detected"); + } } private string GetSpeakers(List speakers, List speakerIds) From ba4a38ab4ad3e0ef5e2e634361e7441c626f7a3e Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:06:42 +0100 Subject: [PATCH 2/6] Add background task to update from sessionize every 30 min --- .../PocketDDD.Server.WebAPI/Program.cs | 3 ++ .../UpdateFromSessionizeBackgroundService.cs | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 PocketDDD.Server/PocketDDD.Server.WebAPI/UpdateFromSessionizeBackgroundService.cs diff --git a/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs b/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs index 6bb707f..7d48356 100644 --- a/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs +++ b/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using PocketDDD.Server.DB; using PocketDDD.Server.Services; +using PocketDDD.Server.WebAPI; using PocketDDD.Server.WebAPI.Authentication; var corsPolicy = "corsPolicy"; @@ -37,6 +38,8 @@ builder.Services.AddHttpClient(); +builder.Services.AddHostedService(); + builder.Services.AddAuthentication() .AddScheme(UserIsRegisteredAuthHandler.SchemeName, null); diff --git a/PocketDDD.Server/PocketDDD.Server.WebAPI/UpdateFromSessionizeBackgroundService.cs b/PocketDDD.Server/PocketDDD.Server.WebAPI/UpdateFromSessionizeBackgroundService.cs new file mode 100644 index 0000000..6d80a80 --- /dev/null +++ b/PocketDDD.Server/PocketDDD.Server.WebAPI/UpdateFromSessionizeBackgroundService.cs @@ -0,0 +1,37 @@ +using PocketDDD.Server.Services; + +namespace PocketDDD.Server.WebAPI; + +public class UpdateFromSessionizeBackgroundService( + IServiceProvider services, + ILogger logger) + : BackgroundService +{ + private ILogger Logger { get; } = logger; + private IServiceProvider Services { get; } = services; + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + Logger.LogInformation("Update from Sessionize background task started."); + + while (!stoppingToken.IsCancellationRequested) + { + Logger.LogInformation("About to update from Sessionize."); + try + { + using var scope = Services.CreateScope(); + + var sessionizeService = scope.ServiceProvider.GetRequiredService(); + await sessionizeService.UpdateFromSessionize(); + + Logger.LogInformation("Update from Sessionize complete."); + } + catch (Exception e) + { + Logger.LogError(e, "Update from Sessionize failed."); + } + + await Task.Delay(TimeSpan.FromMinutes(30), stoppingToken); + } + } +} \ No newline at end of file From 73f30fb66f35c83b180152283ae18911590e7dd6 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:37:56 +0100 Subject: [PATCH 3/6] Add caching to event data --- .../Services/FakePocketDDDApiService.cs | 1 + .../EventDataService.cs | 110 ++++++++++-------- .../PocketDDD.Server.WebAPI/Program.cs | 2 + .../API/ResponseDTOs/EventDataResponseDTO.cs | 10 +- 4 files changed, 69 insertions(+), 54 deletions(-) diff --git a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs index 7bd31e8..2449c9f 100644 --- a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs +++ b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs @@ -25,6 +25,7 @@ public void SetUserAuthToken(string token) return new EventDataResponseDTO { + Id = 1, Version = 1, TimeSlots = new[] { diff --git a/PocketDDD.Server/PocketDDD.Server.Services/EventDataService.cs b/PocketDDD.Server/PocketDDD.Server.Services/EventDataService.cs index 484f440..d719f04 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/EventDataService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/EventDataService.cs @@ -1,63 +1,79 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; using PocketDDD.Server.DB; -using PocketDDD.Server.Model.DTOs; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using PocketDDD.Shared.API.RequestDTOs; using PocketDDD.Shared.API.ResponseDTOs; namespace PocketDDD.Server.Services; -public class EventDataService + +public class EventDataService(PocketDDDContext dbContext, IMemoryCache memoryCache, ILogger logger) { - private readonly PocketDDDContext dbContext; + private const string FetchLatestEventDataCacheKey = nameof(FetchLatestEventData); + private const string FetchCurrentEventDetailIdCacheKey = nameof(FetchCurrentEventDetailId); - public EventDataService(PocketDDDContext dbContext) + public async Task FetchCurrentEventDetailId() { - this.dbContext = dbContext; + if (memoryCache.TryGetValue(FetchCurrentEventDetailIdCacheKey, out var cachedEventDetailId)) + return cachedEventDetailId!.Value; + + cachedEventDetailId = await dbContext.EventDetail.MaxAsync(e => e.Id); + memoryCache.Set(FetchCurrentEventDetailIdCacheKey, cachedEventDetailId, TimeSpan.FromMinutes(5)); + + return cachedEventDetailId.Value; } - public async Task FetchLatestEventData(EventDataUpdateRequestDTO requestDTO) + public async Task FetchLatestEventData(EventDataUpdateRequestDTO requestDto) { - var eventDetails = await dbContext.EventDetail - .Include(x => x.TimeSlots) - .Include(x => x.Tracks) - .Include(x => x.Sessions) - .SingleAsync(x => x.Id == 1); - - if (requestDTO.Version == eventDetails!.Version) + var currentEventDetailId = await FetchCurrentEventDetailId(); + + if (memoryCache.TryGetValue(FetchLatestEventDataCacheKey, out var latestEventData)) + { + logger.LogDebug("Retrieved latest event data from the cache {eventData}", latestEventData); + } + else + { + logger.LogDebug("No event data in the cache, retrieving from the db"); + latestEventData = await dbContext.EventDetail + .AsNoTracking() + .AsSingleQuery() + .Select(eventDetails => new EventDataResponseDTO + { + Id = eventDetails.Id, + Version = eventDetails.Version, + TimeSlots = eventDetails.TimeSlots.Select(ts => new TimeSlotDTO + { + Id = ts.Id, + Info = ts.Info, + From = ts.From, + To = ts.To + }).ToList(), + Tracks = eventDetails.Tracks.Select(t => new TrackDTO + { + Id = t.Id, + Name = t.Name, + RoomName = t.RoomName + }).ToList(), + Sessions = eventDetails.Sessions.Select(s => new SessionDTO + { + Id = s.Id, + Title = s.Title, + ShortDescription = s.ShortDescription, + FullDescription = s.FullDescription, + Speaker = s.Speaker, + TimeSlotId = s.TimeSlot.Id, + TrackId = s.Track.Id + }).ToList() + }) + .SingleAsync(e => e.Id == currentEventDetailId); + + memoryCache.Set(FetchLatestEventDataCacheKey, latestEventData, TimeSpan.FromMinutes(5)); + logger.LogDebug("Updated the latest event data in the cache {eventData}", latestEventData); + } + + if (requestDto.Version >= latestEventData!.Version) return null; - var dtoResponse = new EventDataResponseDTO - { - Version = eventDetails.Version, - TimeSlots = eventDetails.TimeSlots.Select(ts => new TimeSlotDTO - { - Id = ts.Id, - Info = ts.Info, - From = ts.From, - To = ts.To - }).ToList(), - Tracks = eventDetails.Tracks.Select(t => new TrackDTO - { - Id = t.Id, - Name = t.Name, - RoomName = t.RoomName - }).ToList(), - Sessions = eventDetails.Sessions.Select(s => new SessionDTO - { - Id = s.Id, - Title = s.Title, - ShortDescription = s.ShortDescription, - FullDescription = s.FullDescription, - Speaker = s.Speaker, - TimeSlotId = s.TimeSlot.Id, - TrackId = s.Track.Id - }).ToList() - }; - - return dtoResponse; + return latestEventData; } } diff --git a/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs b/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs index 7d48356..329e43f 100644 --- a/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs +++ b/PocketDDD.Server/PocketDDD.Server.WebAPI/Program.cs @@ -29,6 +29,8 @@ options => options.UseSqlServer("name=ConnectionStrings:PocketDDDContext") ); +builder.Services.AddMemoryCache(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/PocketDDD.Shared/API/ResponseDTOs/EventDataResponseDTO.cs b/PocketDDD.Shared/API/ResponseDTOs/EventDataResponseDTO.cs index d82a5bb..f1344c2 100644 --- a/PocketDDD.Shared/API/ResponseDTOs/EventDataResponseDTO.cs +++ b/PocketDDD.Shared/API/ResponseDTOs/EventDataResponseDTO.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace PocketDDD.Shared.API.ResponseDTOs; -namespace PocketDDD.Shared.API.ResponseDTOs; public record EventDataResponseDTO { + public int Id { get; init; } public int Version { get; set; } public IEnumerable TimeSlots { get; set; } = Enumerable.Empty(); public IEnumerable Tracks { get; set; } = Enumerable.Empty(); @@ -37,4 +33,4 @@ public class SessionDTO public string Speaker { get; set; } = ""; public int TrackId { get; set; } public int TimeSlotId { get; set; } -} +} \ No newline at end of file From 8f331bece10cd5e6155a1aeebed5e38344023d39 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:39:29 +0100 Subject: [PATCH 4/6] Fix issue where break slots didn't update from sessionize --- .../PocketDDD.Server.Services/SessionizeService.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs index 84715f6..0924c74 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs @@ -86,11 +86,12 @@ public async Task UpdateFromSessionize() { EventDetail = dbEvent, From = item.startsAt, - To = item.endsAt, - Info = item.isServiceSession ? item.serviceSessionDetails : null + To = item.endsAt }; dbContext.TimeSlots.Add(dbTimeSlot); } + + dbTimeSlot.Info = item.isServiceSession ? item.serviceSessionDetails : null; } if (dbContext.ChangeTracker.HasChanges()) { From 51b4da23ad98f414da7fd8491479a7de126a09c8 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:42:30 +0100 Subject: [PATCH 5/6] Increase the event details version when update from sessionize changes things This allows changes to filter to the client --- .../Services/FakePocketDDDApiService.cs | 2 +- .../PocketDDD.Server.Services/SessionizeService.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs index 2449c9f..0a2e9a3 100644 --- a/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs +++ b/PocketDDD.BlazorClient/PocketDDD.BlazorClient/Services/FakePocketDDDApiService.cs @@ -26,7 +26,7 @@ public void SetUserAuthToken(string token) new EventDataResponseDTO { Id = 1, - Version = 1, + Version = 0, //Set to 0 so if we ever connect this to a real API then it will update! TimeSlots = new[] { new TimeSlotDTO diff --git a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs index 0924c74..d39a263 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs @@ -60,6 +60,7 @@ public async Task UpdateFromSessionize() if (dbContext.ChangeTracker.HasChanges()) { + dbEvent.Version++; Logger.LogInformation("Updating db with changes to rooms"); await dbContext.SaveChangesAsync(); } @@ -67,7 +68,7 @@ public async Task UpdateFromSessionize() { Logger.LogInformation("No changes to rooms were detected"); } - + Logger.LogInformation("Looking for changes to time slots and breaks"); var dbTimeSlots = await dbContext.TimeSlots.ToListAsync(); @@ -93,8 +94,10 @@ public async Task UpdateFromSessionize() dbTimeSlot.Info = item.isServiceSession ? item.serviceSessionDetails : null; } + if (dbContext.ChangeTracker.HasChanges()) { + dbEvent.Version++; Logger.LogInformation("Updating db with changes to time slots and breaks"); await dbContext.SaveChangesAsync(); } @@ -135,8 +138,10 @@ public async Task UpdateFromSessionize() dbSession.Track = dbTracks.Single(x => x.SessionizeId == item.roomId); dbSession.TimeSlot = GetTimeSlot(dbTimeSlots, item.startsAt, item.endsAt); } + if (dbContext.ChangeTracker.HasChanges()) { + dbEvent.Version++; Logger.LogInformation("Updating db with changes to sessions"); await dbContext.SaveChangesAsync(); } From 46d8f6ed2fb4885cfedfee04b8cdd53ba55442f7 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:55:03 +0100 Subject: [PATCH 6/6] Remove hard coding to eventID 1 This will allow us to support multiple events in the future but for now it means we don't have to keep resetting the ID on the EventDetail table --- .../Migrations/2025_SeedData.sql | 12 ---------- .../RegistrationService.cs | 24 ++++++------------- .../SessionizeService.cs | 11 +++++---- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/PocketDDD.Server/PocketDDD.Server.DB/Migrations/2025_SeedData.sql b/PocketDDD.Server/PocketDDD.Server.DB/Migrations/2025_SeedData.sql index 6eb2316..e492487 100644 --- a/PocketDDD.Server/PocketDDD.Server.DB/Migrations/2025_SeedData.sql +++ b/PocketDDD.Server/PocketDDD.Server.DB/Migrations/2025_SeedData.sql @@ -8,18 +8,6 @@ delete TimeSlots delete Tracks delete EventDetail - -GO - --- Reset the identity columns -DBCC CHECKIDENT ('[Tracks]', RESEED, 0); -DBCC CHECKIDENT ('[TimeSlots]', RESEED, 0); -DBCC CHECKIDENT ('[Sessions]', RESEED, 0); - --- There is hardcoding to EventDetail ID 1 so we reset to 1 not 0 -DBCC CHECKIDENT ('[EventDetail]', RESEED, 1); -- Use if this is a brand new table that has never been used before ---DBCC CHECKIDENT ('[EventDetail]', RESEED, 0); -- Use if this is an empty table that used to have rows - GO -- Add 2025 Sessionize ID diff --git a/PocketDDD.Server/PocketDDD.Server.Services/RegistrationService.cs b/PocketDDD.Server/PocketDDD.Server.Services/RegistrationService.cs index 0cf91c9..eb29e10 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/RegistrationService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/RegistrationService.cs @@ -1,30 +1,20 @@ -using PocketDDD.Server.DB; +using System.Security.Cryptography; +using PocketDDD.Server.DB; using PocketDDD.Server.Model.DBModel; -using PocketDDD.Server.Model.DTOs; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; using PocketDDD.Shared.API.RequestDTOs; using PocketDDD.Shared.API.ResponseDTOs; namespace PocketDDD.Server.Services; -public class RegistrationService -{ - private readonly PocketDDDContext dbContext; - - public RegistrationService(PocketDDDContext dbContext) - { - this.dbContext = dbContext; - } +public class RegistrationService(PocketDDDContext dbContext, EventDataService eventDataService) +{ public async Task Register(RegisterDTO dto) { + var currentEventDetailId = await eventDataService.FetchCurrentEventDetailId(); + var user = new User { - EventDetailId = 1, + EventDetailId = currentEventDetailId, Name = dto.Name, Token = GenerateBearerToken(), EventScore = 1 diff --git a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs index d39a263..bba0b3e 100644 --- a/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs +++ b/PocketDDD.Server/PocketDDD.Server.Services/SessionizeService.cs @@ -27,7 +27,7 @@ public async Task UpdateFromSessionize() { Logger.LogInformation("Looking for event detail in database"); - var dbEvent = await dbContext.EventDetail.SingleAsync(x => x.Id == 1); + var dbEvent = await dbContext.EventDetail.OrderBy(x => x.Id).LastAsync(); var sessionizeEventId = dbEvent.SessionizeId; Logger.LogInformation("About to get data from Sessionize API"); @@ -40,7 +40,7 @@ public async Task UpdateFromSessionize() Logger.LogInformation("Information retrieved from Sessionize API"); Logger.LogInformation("Looking for changes to rooms"); - var dbTracks = await dbContext.Tracks.ToListAsync(); + var dbTracks = await dbContext.Tracks.Where(track => track.EventDetail.Id == dbEvent.Id).ToListAsync(); foreach (var item in sessionizeEvent.rooms) { var dbTrack = dbTracks.SingleOrDefault(x => x.SessionizeId == item.id); @@ -71,7 +71,8 @@ public async Task UpdateFromSessionize() Logger.LogInformation("Looking for changes to time slots and breaks"); - var dbTimeSlots = await dbContext.TimeSlots.ToListAsync(); + var dbTimeSlots = await dbContext.TimeSlots.Where(timeSlot => timeSlot.EventDetail.Id == dbEvent.Id) + .ToListAsync(); var sessionizeTimeSlots = sessionizeEvent.sessions .Select(x => (x.startsAt, x.endsAt, x.isServiceSession, serviceSessionDetails: x.isServiceSession ? x.title : null)) @@ -107,8 +108,8 @@ public async Task UpdateFromSessionize() } Logger.LogInformation("Looking for changes to sessions"); - - var dbSessions = await dbContext.Sessions.ToListAsync(); + + var dbSessions = await dbContext.Sessions.Where(session => session.EventDetail.Id == dbEvent.Id).ToListAsync(); var speakers = sessionizeEvent.speakers; dbTracks = await dbContext.Tracks.ToListAsync(); dbTimeSlots = await dbContext.TimeSlots.ToListAsync();