feat(dal, templateMatcher): небольшое улучшение быстродействия синхронизации, ShortcodesService добавлен проброс unitInTemplates для корректного подстановки шорткода %МАКС:...%
This commit is contained in:
@@ -355,7 +355,7 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
var maxShortcodes = MaxShortcodeRegex.Matches(result);
|
||||
if (maxShortcodes.Count > 0)
|
||||
{
|
||||
result = await ReplaceMaxShortcodesAsync(data.Job.Group.Id, data.UnitId, result, maxShortcodes, caller).ConfigureAwait(false);
|
||||
result = await ReplaceMaxShortcodesAsync(data.Job.Group.Id, data.UnitId, result, maxShortcodes, caller, data.UnitsInTemplate).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,7 +675,13 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
return resultName;
|
||||
}
|
||||
|
||||
private async Task<string> ReplaceMaxShortcodesAsync(Guid jobGroupId, Guid unitId, string input, MatchCollection maxShortcodes, string caller)
|
||||
private async Task<string> ReplaceMaxShortcodesAsync(
|
||||
Guid jobGroupId,
|
||||
Guid unitId,
|
||||
string input,
|
||||
MatchCollection maxShortcodes,
|
||||
string caller,
|
||||
List<UnitInTemplateForShortcodes> unitsInTemplateForCurrentTemplate = null)
|
||||
{
|
||||
if (jobGroupId == Guid.Empty)
|
||||
{
|
||||
@@ -703,7 +709,7 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
logger.LogDebug("[{Caller}] Обработка {Shortcode} для JobGroup {JobGroupId}, Template.UnitId {UnitId}, fieldName {FieldName}",
|
||||
caller, fullShortcode, jobGroupId, unitId, fieldName);
|
||||
|
||||
var mostFrequentValue = await GetMaxShortCodeFromCacheOrDbAsync(jobGroupId, unitId, fullShortcode, fieldName, caller).ConfigureAwait(false);
|
||||
var mostFrequentValue = await GetMaxShortCodeFromCacheOrDbAsync(jobGroupId, unitId, fullShortcode, fieldName, caller, unitsInTemplateForCurrentTemplate).ConfigureAwait(false);
|
||||
|
||||
foreach (var match in matches)
|
||||
input = input.Replace(match.Value, mostFrequentValue);
|
||||
@@ -712,7 +718,13 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
return input;
|
||||
}
|
||||
|
||||
private async Task<string> GetMaxShortCodeFromCacheOrDbAsync(Guid jobGroupId, Guid unitId, string fullShortcode, string fieldName, string caller)
|
||||
private async Task<string> GetMaxShortCodeFromCacheOrDbAsync(
|
||||
Guid jobGroupId,
|
||||
Guid unitId,
|
||||
string fullShortcode,
|
||||
string fieldName,
|
||||
string caller,
|
||||
List<UnitInTemplateForShortcodes> unitsInTemplateForCurrentTemplate = null)
|
||||
{
|
||||
if (jobGroupId == Guid.Empty)
|
||||
{
|
||||
@@ -737,21 +749,7 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
|
||||
logger.LogDebug("[{Caller}] Кэш промахнут для GroupedShortCode '{Name}'. Запрашиваем из БД.", caller, fullShortcode);
|
||||
|
||||
// Загружаем юниты из БД
|
||||
var effectiveUnitIds = await jobService.Get()
|
||||
.Where(j => j.GroupId == jobGroupId)
|
||||
.Join(
|
||||
templateService.Get()
|
||||
.Where(t => t.StatusTypeId == TemplateStatusTypeEnum.Used && t.UnitId == unitId)
|
||||
.Include(t => t.UnitsInTemplate),
|
||||
job => job.Id,
|
||||
template => template.JobId,
|
||||
(job, template) => template
|
||||
)
|
||||
.SelectMany(template => template.UnitsInTemplate)
|
||||
.Select(uit => uit.UnitId)
|
||||
.Distinct()
|
||||
.ToListAsync().ConfigureAwait(false);
|
||||
var effectiveUnitIds = await GetEffectiveUnitIdsAsync(jobGroupId, unitId, unitsInTemplateForCurrentTemplate, caller).ConfigureAwait(false);
|
||||
|
||||
logger.LogDebug("[{Caller}] EffectiveUnitIds: [{Ids}], Count: {Count}", caller, string.Join(", ", effectiveUnitIds), effectiveUnitIds.Count);
|
||||
|
||||
@@ -778,6 +776,47 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
return NoContent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получает список UnitId для подстановки шорткода %МАКС:...%.
|
||||
/// Сначала пробует использовать переданные юниты, затем загружает из БД.
|
||||
/// </summary>
|
||||
/// <param name="jobGroupId">ID JobGroup, для которого ищутся юниты</param>
|
||||
/// <param name="unitId">ID ключевого юнита шаблона</param>
|
||||
/// <param name="unitsInTemplateForCurrentTemplate">Юниты, переданные с текущим шаблоном (опционально)</param>
|
||||
/// <param name="caller">Имя вызывающего метода (для логирования)</param>
|
||||
/// <returns>Список UnitId</returns>
|
||||
private async Task<List<Guid>> GetEffectiveUnitIdsAsync(
|
||||
Guid jobGroupId,
|
||||
Guid unitId,
|
||||
List<UnitInTemplateForShortcodes> unitsInTemplateForCurrentTemplate,
|
||||
string caller)
|
||||
{
|
||||
if (unitsInTemplateForCurrentTemplate != null && unitsInTemplateForCurrentTemplate.Count > 0)
|
||||
{
|
||||
logger.LogDebug("[{Caller}] Используем UnitsInTemplate из входных данных.", caller);
|
||||
return unitsInTemplateForCurrentTemplate.Select(uit => uit.UnitId).ToList();
|
||||
}
|
||||
|
||||
logger.LogDebug("[{Caller}] Загружаем UnitsInTemplate из БД.", caller);
|
||||
|
||||
var effectiveUnitIds = await jobService.Get()
|
||||
.Where(j => j.GroupId == jobGroupId)
|
||||
.Join(
|
||||
templateService.Get()
|
||||
.Where(t => t.StatusTypeId == TemplateStatusTypeEnum.Used && t.UnitId == unitId)
|
||||
.Include(t => t.UnitsInTemplate),
|
||||
job => job.Id,
|
||||
template => template.JobId,
|
||||
(job, template) => template
|
||||
)
|
||||
.SelectMany(template => template.UnitsInTemplate)
|
||||
.Select(uit => uit.UnitId)
|
||||
.Distinct()
|
||||
.ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return effectiveUnitIds;
|
||||
}
|
||||
|
||||
private async Task<string> ReplaceLettersShortcodesAsync(Guid unitId, string input, MatchCollection lettersShortcodes, string caller)
|
||||
{
|
||||
var shortcodeToMatches = lettersShortcodes
|
||||
|
||||
Reference in New Issue
Block a user