forked from ddrilling/AsbCloudServer
Добавление записей в кэш для каждой скважины
This commit is contained in:
parent
787fd478eb
commit
aa5c67d2e7
@ -109,71 +109,64 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationBaseDto,
|
||||
|
||||
public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)
|
||||
{
|
||||
var keyCacheSections = $"OperationsBySectionSummaries_{string.Join('_', idsWells.OrderBy(x => x))}";
|
||||
const string keyCacheTemplate = "OperationsBySectionSummaries_{0}";
|
||||
|
||||
var cache = await memoryCache.GetOrCreateAsync(keyCacheSections, async (entry) =>
|
||||
var result = new List<SectionByOperationsDto>();
|
||||
|
||||
foreach (var idWell in idsWells)
|
||||
{
|
||||
var sections = await memoryCache.GetOrCreateAsync(string.Format(keyCacheTemplate, idWell), async (entry) =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30);
|
||||
|
||||
var query = dbContext.Set<WellOperation>()
|
||||
.Where(x => x.IdWell == idWell)
|
||||
.GroupBy(operation => new
|
||||
{
|
||||
operation.IdWell,
|
||||
operation.IdType,
|
||||
operation.IdWellSectionType,
|
||||
operation.WellSectionType.Caption,
|
||||
operation.IdType, operation.IdWellSectionType, operation.WellSectionType.Caption,
|
||||
})
|
||||
.Select(group => new
|
||||
{
|
||||
group.Key.IdWell,
|
||||
group.Key.IdType,
|
||||
group.Key.IdWellSectionType,
|
||||
group.Key.Caption,
|
||||
|
||||
First = group
|
||||
.OrderBy(operation => operation.DateStart)
|
||||
.Select(operation => new
|
||||
{
|
||||
operation.DateStart,
|
||||
operation.DepthStart,
|
||||
})
|
||||
.Select(operation => new { operation.DateStart, operation.DepthStart, })
|
||||
.First(),
|
||||
|
||||
Last = group
|
||||
.OrderByDescending(operation => operation.DateStart)
|
||||
.Select(operation => new
|
||||
{
|
||||
operation.DateStart,
|
||||
operation.DurationHours,
|
||||
operation.DepthEnd,
|
||||
operation.DateStart, operation.DurationHours, operation.DepthEnd,
|
||||
})
|
||||
.First(),
|
||||
})
|
||||
.Where(s => idsWells.Contains(s.IdWell));
|
||||
});
|
||||
|
||||
var dbData = await query.ToArrayAsync(token);
|
||||
|
||||
var sections = dbData.Select(
|
||||
item => new SectionByOperationsDto
|
||||
{
|
||||
IdWell = item.IdWell,
|
||||
IdWell = idWell,
|
||||
IdType = item.IdType,
|
||||
IdWellSectionType = item.IdWellSectionType,
|
||||
|
||||
Caption = item.Caption,
|
||||
|
||||
DateStart = item.First.DateStart,
|
||||
DepthStart = item.First.DepthStart,
|
||||
|
||||
DateEnd = item.Last.DateStart.AddHours(item.Last.DurationHours),
|
||||
DepthEnd = item.Last.DepthEnd,
|
||||
})
|
||||
.ToArray()
|
||||
.AsEnumerable();
|
||||
});
|
||||
|
||||
|
||||
entry.Value = sections;
|
||||
return sections;
|
||||
});
|
||||
|
||||
return cache!;
|
||||
result.AddRange(sections!);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
|
||||
|
Loading…
Reference in New Issue
Block a user