Enhance query performance by applying AsSplitQuery to multiple handlers and loaders for Channels and ScheduleTemplates, improving efficiency in data retrieval and reducing unnecessary data duplication in queries.
This commit is contained in:
@@ -60,6 +60,10 @@ public sealed class GridScheduleGenerator(
|
||||
var channel = await dbContext
|
||||
.Channels.Include(c => c.BumperTemplates)
|
||||
.ThenInclude(t => t.Variants)
|
||||
// Вложенные коллекции тянем отдельными запросами: иначе колонки родителя (у шаблона —
|
||||
// jsonb с правилами, у слоя — jsonb применимости) приезжают по копии на каждую строку
|
||||
// листа. Тик планировщика повторяет эти два запроса на каждый канал.
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(c => c.Id == channelId, cancellationToken);
|
||||
if (channel is null || !channel.IsEnabled || channel.TemplateId is null)
|
||||
return new GenerationReport(0, [], ChannelSkipped: true);
|
||||
@@ -70,6 +74,7 @@ public sealed class GridScheduleGenerator(
|
||||
var template = await dbContext
|
||||
.ScheduleTemplates.Include(t => t.Layers)
|
||||
.ThenInclude(l => l.Slots)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == channel.TemplateId, cancellationToken);
|
||||
if (template is null)
|
||||
return new GenerationReport(0, [], ChannelSkipped: true);
|
||||
@@ -174,6 +179,7 @@ public sealed class GridScheduleGenerator(
|
||||
.Channels.AsNoTracking()
|
||||
.Include(c => c.BumperTemplates)
|
||||
.ThenInclude(t => t.Variants)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(c => c.Id == channelId, cancellationToken);
|
||||
if (channel is null || channel.TemplateId is null)
|
||||
return null;
|
||||
@@ -182,6 +188,7 @@ public sealed class GridScheduleGenerator(
|
||||
.ScheduleTemplates.AsNoTracking()
|
||||
.Include(t => t.Layers)
|
||||
.ThenInclude(l => l.Slots)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == channel.TemplateId, cancellationToken);
|
||||
if (template is null)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user