diff --git a/src/FilterLists.Services/FilterList/FilterListService.cs b/src/FilterLists.Services/FilterList/FilterListService.cs index 97b1a5771..b6025d9ad 100644 --- a/src/FilterLists.Services/FilterList/FilterListService.cs +++ b/src/FilterLists.Services/FilterList/FilterListService.cs @@ -18,39 +18,8 @@ public FilterListService(FilterListsDbContext dbContext, IMapper mapper) : base( { } - public async Task> GetAllSummariesAsync() - { - var summaries = await GetSummaryDtos(); - var latestSnapshots = await GetLatestSnapshots(); - return summaries.GroupJoin(latestSnapshots, summary => summary.Id, snap => snap.FilterListId, - (summary, snap) => - { - snap = snap as Data.Entities.Snapshot[] ?? snap.ToArray(); - var updatedDate = snap.Any() ? snap.Single().CreatedDateUtc : (DateTime?) null; - return new ListSummaryDto - { - Id = summary.Id, - AddedDate = summary.AddedDate, - Languages = summary.Languages, - Name = summary.Name, - UpdatedDate = updatedDate, - ViewUrl = summary.ViewUrl - }; - }); - } - - private async Task> GetSummaryDtos() => - await DbContext.FilterLists.OrderBy(l => l.Name) - .ProjectTo(Mapper.ConfigurationProvider) - .ToListAsync(); - - private async Task> GetLatestSnapshots() => - await DbContext.Snapshots.AsNoTracking() - .Where(s => s.IsCompleted && s.HttpStatusCode == "200" && - (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) - .GroupBy(s => s.FilterListId, - (key, x) => x.OrderByDescending(y => y.CreatedDateUtc).First()) - .ToListAsync(); + public async Task> GetAllSummariesAsync() => + await DbContext.FilterLists.ProjectTo(Mapper.ConfigurationProvider).ToListAsync(); public async Task GetDetailsAsync(uint id) { @@ -79,7 +48,7 @@ private async Task GetActiveRuleCount(ListDetailsDto details) s.RemovedSnapshotRules.Count > 0)) .Select(s => s.CreatedDateUtc) .OrderByDescending(s => s.Date); - return snapshotDates.Any() ? (DateTime?) await snapshotDates.FirstAsync() : null; + return snapshotDates.Any() ? (DateTime?)await snapshotDates.FirstAsync() : null; } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles.cs b/src/FilterLists.Services/FilterList/MappingProfiles.cs index f45579a10..65822a577 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using AutoMapper; using FilterLists.Data.Entities; using FilterLists.Services.FilterList.Models; @@ -21,7 +22,16 @@ private void CreateListSummaryDtoMap() => CreateMap() .ForMember(dto => dto.Languages, conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))) - .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)); + .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)) + .ForMember(dto => dto.UpdatedDate, + conf => conf.MapFrom(list => + list.Snapshots.Where(s => + s.IsCompleted && s.HttpStatusCode == "200" && + (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) + .OrderByDescending(s => s.CreatedDateUtc) + .Select(s => s.CreatedDateUtc) + .Cast() + .FirstOrDefault())); private void CreateListDetailsDtoMap() => CreateMap()