From 0b72291e0aca3a0cf74551abf4183579483d69d3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 6 Dec 2019 08:28:30 +0000 Subject: [PATCH 1/3] Use new field "sum_queries" for displaying the total queries number on the dashboard. This avoids to necessity to sum all individual query types. Furthermore (and more important), it greatly simplifies the database queries as we do not need to count the different query types indicidually. Signed-off-by: DL6ER --- src/components/dashboard/SummaryStats.tsx | 4 +--- src/types/api.d.ts | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/dashboard/SummaryStats.tsx b/src/components/dashboard/SummaryStats.tsx index f2b9a57..d26d771 100644 --- a/src/components/dashboard/SummaryStats.tsx +++ b/src/components/dashboard/SummaryStats.tsx @@ -96,9 +96,7 @@ class SummaryStats extends Component { * @returns {*} the transformed props */ export const transformData = (data: ApiSummary): SummaryStatsProps => ({ - totalQueries: Object.keys(data.total_queries) - .reduce((total, queryType) => total + data.total_queries[queryType], 0) - .toLocaleString(), + totalQueries: data.sum_queries.toLocaleString(), blockedQueries: data.blocked_queries.toLocaleString(), percentBlocked: data.percent_blocked.toFixed(2).toLocaleString() + "%", gravityDomains: data.gravity_size.toLocaleString(), diff --git a/src/types/api.d.ts b/src/types/api.d.ts index f7464a2..b8af86a 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -134,6 +134,7 @@ interface ApiQueryType { interface ApiSummary { gravity_size: number; + sum_queries: number; total_queries: { A: number; AAAA: number; From a5a60ce82bbc55d159ca9e14b7aec47fe2e9902c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 6 Dec 2019 08:35:44 +0000 Subject: [PATCH 2/3] Adjust tests and fake-data Signed-off-by: DL6ER --- scripts/make-fake-data.js | 1 + src/components/dashboard/__tests__/SummaryStats.test.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/make-fake-data.js b/scripts/make-fake-data.js index 1ef623c..613e2d7 100644 --- a/scripts/make-fake-data.js +++ b/scripts/make-fake-data.js @@ -87,6 +87,7 @@ function summary() { return { gravity_size: faker.random.number(), + sum_queries: total, total_queries: { A: queryTypeTotals[0], AAAA: queryTypeTotals[1], diff --git a/src/components/dashboard/__tests__/SummaryStats.test.tsx b/src/components/dashboard/__tests__/SummaryStats.test.tsx index a5e9907..0bc6474 100644 --- a/src/components/dashboard/__tests__/SummaryStats.test.tsx +++ b/src/components/dashboard/__tests__/SummaryStats.test.tsx @@ -20,6 +20,7 @@ const tick = global.tick; const fakeData: ApiSummary = { active_clients: 2, + sum_queries: 22813, blocked_queries: 2281, cached_queries: 3573, forwarded_queries: 19154, From 6c43a90d92ce9c7587c4c9b226952f4307b5ff08 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 11 Dec 2019 18:06:24 +0200 Subject: [PATCH 3/3] Run prettier for all js and tsx files Signed-off-by: XhmikosR --- package.json | 4 ++-- scripts/generate-language-list.js | 6 +++--- scripts/make-fake-data.js | 16 +++++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 07527d8..499909a 100644 --- a/package.json +++ b/package.json @@ -86,8 +86,8 @@ "test": "react-scripts test --env=jsdom", "coverage": "react-scripts test --env=jsdom --coverage", "eject": "react-scripts eject", - "format": "prettier --write \"src/**/*.tsx\"", - "check-format": "prettier --list-different \"src/**/*.tsx\"" + "format": "prettier --write \"**/*.{js,tsx}\"", + "check-format": "prettier --list-different \"**/*.{js,tsx}\"" }, "browserslist": [ ">0.2%", diff --git a/scripts/generate-language-list.js b/scripts/generate-language-list.js index 292da56..0e7e2c0 100644 --- a/scripts/generate-language-list.js +++ b/scripts/generate-language-list.js @@ -15,9 +15,9 @@ const ISO6391 = require("iso-639-1"); const languages = fs.readdirSync("public/i18n"); const languageMap = languages.map(lang => { return { - "code": lang, - "name": ISO6391.getName(lang) - } + code: lang, + name: ISO6391.getName(lang) + }; }); // Save the language list so the web interface knows what's available diff --git a/scripts/make-fake-data.js b/scripts/make-fake-data.js index 613e2d7..20fc316 100644 --- a/scripts/make-fake-data.js +++ b/scripts/make-fake-data.js @@ -56,8 +56,8 @@ function history(length) { client: isHostname ? faker.internet.domainWord() + ".local" : isIPv4 - ? faker.internet.ip() - : faker.internet.ipv6(), + ? faker.internet.ip() + : faker.internet.ipv6(), dnssec: Math.floor(Math.random() * 5.9), reply: Math.floor(Math.random() * 7.9), response_time: Math.floor(Math.random() * 100.9) @@ -381,7 +381,7 @@ function getPreferences() { return { layout: "boxed", language: "en" - } + }; } console.log("Deleting old fake API data..."); @@ -412,14 +412,20 @@ write("public/fakeAPI/stats/top_domains", topDomains(10)); write("public/fakeAPI/stats/top_clients", topClients(10)); write("public/fakeAPI/stats/top_blocked_clients", topBlockedClients(10)); write("public/fakeAPI/stats/database/overTime/history", historyOverTime(144)); -write("public/fakeAPI/stats/database/overTime/clients", clientsOverTime(144, 5)); +write( + "public/fakeAPI/stats/database/overTime/clients", + clientsOverTime(144, 5) +); write("public/fakeAPI/stats/database/summary", summary()); write("public/fakeAPI/stats/database/query_types", queryTypes()); write("public/fakeAPI/stats/database/upstreams", upstreams(3)); write("public/fakeAPI/stats/database/top_blocked", topBlockedDomains(10)); write("public/fakeAPI/stats/database/top_domains", topDomains(10)); write("public/fakeAPI/stats/database/top_clients", topClients(10)); -write("public/fakeAPI/stats/database/top_blocked_clients", topBlockedClients(10)); +write( + "public/fakeAPI/stats/database/top_blocked_clients", + topBlockedClients(10) +); write("public/fakeAPI/auth", auth()); write("public/fakeAPI/version", getVersionInfo());