From 8d8b18f2b9d9690a27036fde7bf95517aa8f2ea4 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Thu, 7 Jun 2018 13:44:07 -0500 Subject: [PATCH] try for perf, count all rules not just all active rules ref #272 --- .../V1/Controllers/RulesController.cs | 2 +- src/FilterLists.Services/RuleService.cs | 11 ++--- .../ClientApp/components/Home.tsx | 44 ++++++++++++------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/FilterLists.Api/V1/Controllers/RulesController.cs b/src/FilterLists.Api/V1/Controllers/RulesController.cs index 2b2f0518e..714bb13ab 100644 --- a/src/FilterLists.Api/V1/Controllers/RulesController.cs +++ b/src/FilterLists.Api/V1/Controllers/RulesController.cs @@ -14,6 +14,6 @@ public RulesController(RuleService ruleService) } [HttpGet] - public async Task Index() => Json(new {Count = await _ruleService.GetCountAllActiveRules()}); + public async Task Index() => Json(new {Count = await _ruleService.GetCountAll()}); } } \ No newline at end of file diff --git a/src/FilterLists.Services/RuleService.cs b/src/FilterLists.Services/RuleService.cs index 2b9933e0d..bc6f41fce 100644 --- a/src/FilterLists.Services/RuleService.cs +++ b/src/FilterLists.Services/RuleService.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using FilterLists.Data; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; @@ -14,10 +13,8 @@ public RuleService(FilterListsDbContext dbContext) : base(dbContext) DbContext = dbContext; } - public async Task GetCountAllActiveRules() => await DbContext - .SnapshotRules.AsNoTracking() - .Where(x => x.RemovedBySnapshotId == null) - .GroupBy(x => x.RuleId) - .CountAsync(); + public async Task GetCountAll() => await DbContext + .Rules.AsNoTracking() + .CountAsync(); } } \ No newline at end of file diff --git a/src/FilterLists.Web/ClientApp/components/Home.tsx b/src/FilterLists.Web/ClientApp/components/Home.tsx index d143eb65d..529f236ce 100644 --- a/src/FilterLists.Web/ClientApp/components/Home.tsx +++ b/src/FilterLists.Web/ClientApp/components/Home.tsx @@ -5,28 +5,32 @@ import ReactTable from "react-table" import "react-table/react-table.css" import ListDetails from "./ListDetails"; -interface IFilterListsState { - filterLists: IFilterListSummaryDto[]; - loading: boolean; +interface IHomeState { + lists: IListDto[]; + loadingLists: boolean; + ruleCount: number; + loadingRuleCount: boolean; } -export class Home extends React.Component, IFilterListsState> { +export class Home extends React.Component, IHomeState> { constructor(props: any) { super(props); this.state = { - filterLists: [], - loading: true + lists: [], + loadingLists: true, + ruleCount: 0, + loadingRuleCount: true }; } render() { - const contents = this.state.loading + const contents = this.state.loadingLists || this.state.loadingRuleCount ?

Loading...

:
- {Home.renderTagline(this.state.filterLists)} - {Home.renderFilterListsTable(this.state.filterLists)} + {Home.renderTagline(this.state.lists, this.state.ruleCount)} + {Home.renderFilterListsTable(this.state.lists)}
; return
{contents} @@ -35,22 +39,30 @@ export class Home extends React.Component, IFilterListsS componentDidMount() { fetch("https://filterlists.com/api/v1/lists") - .then(response => response.json() as Promise) + .then(response => response.json() as Promise) .then(data => { this.setState({ - filterLists: data, - loading: false + lists: data, + loadingLists: false + }); + }); + fetch("https://filterlists.com/api/v1/rules") + .then(response => response.json() as Promise) + .then(data => { + this.setState({ + ruleCount: data, + loadingRuleCount: false }); }); } - private static renderTagline(filterLists: IFilterListSummaryDto[]) { + private static renderTagline(filterLists: IListDto[], ruleCount: number) { return

- The independent, comprehensive directory of {filterLists.length} filter and host lists for advertisements, trackers, malware, and annoyances. + The independent, comprehensive directory of {ruleCount} unique rules across {filterLists.length} filter and host lists for advertisements, trackers, malware, and annoyances.

; } - private static renderFilterListsTable(filterLists: IFilterListSummaryDto[]) { + private static renderFilterListsTable(filterLists: IListDto[]) { return , IFilterListsS } } -interface IFilterListSummaryDto { +interface IListDto { id: number; name: string; languages: IListLanguageDto[];