From d11451a22a666f4cda433e535f991546cf8ced16 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 14 Jan 2019 21:02:31 -0800 Subject: [PATCH] Remove outdated scripts --- scripts/clear-cache.js | 25 ------------------ scripts/show-stats.js | 58 ------------------------------------------ 2 files changed, 83 deletions(-) delete mode 100644 scripts/clear-cache.js delete mode 100644 scripts/show-stats.js diff --git a/scripts/clear-cache.js b/scripts/clear-cache.js deleted file mode 100644 index afcf6cf..0000000 --- a/scripts/clear-cache.js +++ /dev/null @@ -1,25 +0,0 @@ -const cache = require("../modules/utils/cache"); - -function getKeys(client, pattern, callback, array = [], cursor = 0) { - client.scan(cursor, "MATCH", pattern, (error, reply) => { - if (error) { - reject(error); - } else { - const next = reply[0]; - const keys = reply[1]; - - array.push.apply(array, keys); - - if (next == 0) { - callback(array); - } else { - getKeys(client, pattern, callback, array, next); - } - } - }); -} - -getKeys(cache, "npmPackageInfo-*", keys => { - console.log(keys); - process.exit(); -}); diff --git a/scripts/show-stats.js b/scripts/show-stats.js deleted file mode 100644 index 78c982b..0000000 --- a/scripts/show-stats.js +++ /dev/null @@ -1,58 +0,0 @@ -const subDays = require("date-fns/sub_days"); -const prettyBytes = require("pretty-bytes"); -const table = require("text-table"); - -const StatsAPI = require("../server/StatsAPI"); -const now = new Date(); - -function createRange(start, end) { - const range = []; - while (start < end) range.push(start++); - return range; -} - -function createPastDays(n) { - return createRange(1, n + 1) - .map(days => subDays(now, days)) - .reverse(); -} - -const pastSevenDays = createPastDays(7); -const pastThirtyDays = createPastDays(30); - -Promise.all([ - StatsAPI.sumKeys( - pastSevenDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`) - ), - StatsAPI.sumKeys( - pastSevenDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`) - ), - StatsAPI.sumKeys( - pastThirtyDays.map(date => `stats-requests-${StatsAPI.createDayKey(date)}`) - ), - StatsAPI.sumKeys( - pastThirtyDays.map(date => `stats-bandwidth-${StatsAPI.createDayKey(date)}`) - ) -]).then(results => { - console.log("\n## Summary"); - console.log("Requests this week: %s", results[0].toLocaleString()); - console.log("Bandwidth this week: %s", prettyBytes(results[1])); - console.log("Requests this month: %s", results[2].toLocaleString()); - console.log("Bandwidth this month: %s", prettyBytes(results[3])); - - StatsAPI.sumTopScores( - pastSevenDays.map( - date => `stats-packageRequests-${StatsAPI.createDayKey(date)}` - ) - ).then(topPackages => { - console.log("\n## Top Packages This Week"); - - topPackages.forEach(result => { - result[1] = result[1].toLocaleString(); - }); - - console.log(table(topPackages)); - - process.exit(); - }); -});