diff --git a/src/FilterLists.Services/FilterList/FilterListService.cs b/src/FilterLists.Services/FilterList/FilterListService.cs index 8ab314849..574745071 100644 --- a/src/FilterLists.Services/FilterList/FilterListService.cs +++ b/src/FilterLists.Services/FilterList/FilterListService.cs @@ -18,13 +18,40 @@ public FilterListService(FilterListsDbContext dbContext) : base(dbContext) } public async Task> GetAllSummariesAsync() + { + var summaries = await GetSummaryDtos(); + var latestUpdatedSnapshots = await GetLatestUpdatedSnapshots(); + return summaries.Join(latestUpdatedSnapshots, summary => summary.Id, snap => snap.FilterListId, + (summary, snap) => new ListSummaryDto + { + Id = summary.Id, + AddedDate = summary.AddedDate, + Languages = summary.Languages, + Name = summary.Name, + UpdatedDate = snap.CreatedDateUtc, + ViewUrl = summary.ViewUrl + }); + } + + private async Task> GetSummaryDtos() { return await DbContext.FilterLists.AsNoTracking() - .OrderBy(x => x.Name) + .OrderBy(list => list.Name) .ProjectTo() .ToListAsync(); } + private async Task> GetLatestUpdatedSnapshots() + { + return await DbContext.Snapshots.AsNoTracking() + .Where(snap => + snap.IsCompleted && + (snap.AddedSnapshotRules.Count > 0 || snap.RemovedSnapshotRules.Count > 0)) + .GroupBy(snap => snap.FilterListId, + (key, x) => x.OrderByDescending(y => y.CreatedDateUtc).First()) + .ToListAsync(); + } + public async Task GetDetailsAsync(int id) { var details = await DbContext.FilterLists.AsNoTracking() @@ -38,27 +65,24 @@ public async Task GetDetailsAsync(int id) private async Task GetActiveRuleCount(ListDetailsDto details) { - return await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted) - .Include(s => s.AddedSnapshotRules) + return await DbContext.Snapshots.AsNoTracking() + .Where(s => s.FilterListId == details.Id && s.IsCompleted) .SelectMany(sr => sr.AddedSnapshotRules) .CountAsync() - - await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted) - .Include(s => s.RemovedSnapshotRules) + await DbContext.Snapshots.AsNoTracking() + .Where(s => s.FilterListId == details.Id && s.IsCompleted) .SelectMany(sr => sr.RemovedSnapshotRules) .CountAsync(); } private async Task GetUpdatedDate(ListDetailsDto details) { - return details.DiscontinuedDate != null - ? (DateTime?) null - : await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted) - .Include(s => s.AddedSnapshotRules) - .Include(s => s.RemovedSnapshotRules) - .Where(s => s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0) - .Select(s => s.CreatedDateUtc) - .OrderByDescending(s => s.Date) - .FirstAsync(); + return await DbContext.Snapshots.AsNoTracking() + .Where(s => s.FilterListId == details.Id && s.IsCompleted && + (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) + .Select(s => s.CreatedDateUtc) + .OrderByDescending(s => s.Date) + .FirstAsync(); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListSummaryDto.cs b/src/FilterLists.Services/FilterList/ListSummaryDto.cs index 67c6309c4..b8cab3dc1 100644 --- a/src/FilterLists.Services/FilterList/ListSummaryDto.cs +++ b/src/FilterLists.Services/FilterList/ListSummaryDto.cs @@ -8,9 +8,10 @@ namespace FilterLists.Services.FilterList public class ListSummaryDto { public int Id { get; set; } - public DateTime CreatedDateUtc { get; set; } + public DateTime AddedDate { get; set; } public IEnumerable Languages { get; set; } public string Name { get; set; } + public DateTime UpdatedDate { get; set; } public string ViewUrl { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles.cs b/src/FilterLists.Services/FilterList/MappingProfiles.cs index 73c5d8afd..457083f58 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles.cs @@ -10,7 +10,8 @@ public MappingProfiles() { CreateMap() .ForMember(dto => dto.Languages, - conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))); + conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))) + .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)); CreateMap() .ForMember(dto => dto.Languages, conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language.Name))) diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx index c55297504..03d9cdd79 100644 --- a/src/FilterLists.Web/ClientApp/components/Home.tsx +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -94,15 +94,28 @@ export class Home extends React.Component, IHomeState> { className: "d-none d-sm-block" }, { - Header: "Added", - accessor: "createdDateUtc", + Header: "Updated", + accessor: "updatedDate", filterable: true, filterMethod: (filter: any, row: any) => row[filter.id].toUpperCase() .includes(filter.value.toUpperCase()), sortMethod: (a: any, b: any) => a > b ? 1 : -1, Cell: (cell: any) =>
{moment(cell.value).format("M-D-YY")}
, style: { whiteSpace: "inherit" }, - width: 70, + width: 75, + headerClassName: "d-none d-sm-block", + className: "d-none d-sm-block" + }, + { + Header: "Added", + accessor: "addedDate", + filterable: true, + filterMethod: (filter: any, row: any) => row[filter.id].toUpperCase() + .includes(filter.value.toUpperCase()), + sortMethod: (a: any, b: any) => a > b ? 1 : -1, + Cell: (cell: any) =>
{moment(cell.value).format("M-D-YY")}
, + style: { whiteSpace: "inherit" }, + width: 75, headerClassName: "d-none d-sm-block", className: "d-none d-sm-block" }, @@ -148,9 +161,10 @@ export class Home extends React.Component, IHomeState> { interface IListDto { id: number; - createdDateUtc: string; + addedDate: string; name: string; languages: IListLanguageDto[]; + updatedDate: string; viewUrl: string; }