1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-06-30 22:46:39 -04:00

get overall stats for /api/hits/ without circular parsing of the RSS feed

This commit is contained in:
2022-01-03 15:29:35 -05:00
parent 4fe47de9ae
commit 6d81939b8b
3 changed files with 51 additions and 98 deletions

View File

@ -14,10 +14,9 @@
"url": "https://github.com/jakejarvis/jarv.is.git"
},
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev",
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"postbuild": "next-sitemap",
"start": "next start",
"analyze": "cross-env ANALYZE=true next build",
"lint": "run-s lint:*",
"lint:next": "next lint",
@ -32,11 +31,9 @@
"@mdx-js/loader": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@next/bundle-analyzer": "^12.0.7",
"@next/mdx": "^12.0.7",
"@octokit/graphql": "^4.8.0",
"@primer/octicons-react": "^16.2.0",
"@sentry/node": "^6.16.1",
"classnames": "^2.3.1",
"copy-to-clipboard": "^3.3.1",
"date-fns": "^2.28.0",
"fathom-client": "^3.2.0",
@ -45,7 +42,6 @@
"gray-matter": "^4.0.3",
"hex-rgb": "^5.0.0",
"highlight.js": "^11.3.1",
"html-entities": "^2.3.2",
"is-absolute-url": "^4.0.1",
"lodash.groupby": "^4.6.0",
"modern-normalize": "github:sindresorhus/modern-normalize#1fc6b5a86676b7ac8abc62d04d6080f92debc70f",
@ -67,7 +63,6 @@
"rehype-external-links": "^1.0.1",
"rehype-highlight": "^5.0.2",
"rehype-slug": "^5.0.1",
"rss-parser": "^3.12.0",
"styled-jsx": "^4.0.1",
"swr": "^1.1.2",
"trim-newlines": "^4.0.2"

View File

@ -1,7 +1,6 @@
import * as Sentry from "@sentry/node";
import * as config from "../../lib/config";
import Parser from "rss-parser";
import { decode } from "html-entities";
import { getAllNotes } from "../../lib/parse-notes";
import pRetry from "p-retry";
import faunadb from "faunadb";
const q = faunadb.query;
@ -84,37 +83,32 @@ const incrementPageHits = async (slug, client) => {
};
const getSiteStats = async (client) => {
// get database and RSS results asynchronously
const parser = new Parser();
const [feed, result] = await Promise.all([
parser.parseURL(`${config.baseUrl}/feed.xml`),
client.query(
q.Map(
q.Paginate(q.Documents(q.Collection("hits")), { size: 99 }),
q.Lambda((x) => q.Select("data", q.Get(x)))
)
),
]);
const notes = getAllNotes();
const { data: pages } = await client.query(
q.Map(
q.Paginate(q.Documents(q.Collection("hits")), { size: 99 }),
q.Lambda((x) => q.Select("data", q.Get(x)))
)
);
const pages = result.data;
const stats = {
total: { hits: 0 },
pages,
};
pages.map((p) => {
pages.map((page: any) => {
// match URLs from RSS feed with db to populate some metadata
const match = feed.items.find((x) => x.link === `${config.baseUrl}/${p.slug}/`);
const match: any = notes.find((note) => `notes/${note.slug}` === page.slug);
if (match) {
p.title = decode(match.title);
p.url = match.link;
p.date = new Date(match.pubDate);
page.title = match.title;
page.url = `${config.baseUrl}/${page.slug}/`;
page.date = match.date;
}
// add these hits to running tally
stats.total.hits += p.hits;
stats.total.hits += page.hits;
return p;
return page;
});
// sort by hits (descending)

106
yarn.lock
View File

@ -1159,11 +1159,6 @@
dependencies:
glob "7.1.7"
"@next/mdx@^12.0.7":
version "12.0.7"
resolved "https://registry.yarnpkg.com/@next/mdx/-/mdx-12.0.7.tgz#5095198e85a0fe6d3687db9813aa373f185dece8"
integrity sha512-yudu/ZxkFznvcQtVKKWkLYVja4kCah/yz09x5tpphr5g+xmaJNA6RylheaORIY8qdgdKRqVXt3hMnpfdH9bBtw==
"@next/react-refresh-utils@12.0.8-canary.14":
version "12.0.8-canary.14"
resolved "https://registry.yarnpkg.com/@next/react-refresh-utils/-/react-refresh-utils-12.0.8-canary.14.tgz#f6906f2a3389626cbefc9571abf108eccac796a4"
@ -1525,9 +1520,9 @@
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
"@types/node@*":
version "17.0.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.6.tgz#cc1589c9ee853b389e67e8fb4384e0f250a139b9"
integrity sha512-+XBAjfZmmivILUzO0HwBJoYkAyyySSLg5KCGBDFLomJo0sV6szvVLAf4ANZZ0pfWzgEds5KmGLG9D5hfEqOhaA==
version "17.0.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.7.tgz#4a53d8332bb65a45470a2f9e2611f1ced637a5cb"
integrity sha512-1QUk+WAUD4t8iR+Oj+UgI8oJa6yyxaB8a8pHaC8uqM6RrS1qbL7bf3Pwl5rHv0psm2CuDErgho6v5N+G+5fwtQ==
"@types/normalize-package-data@^2.4.0":
version "2.4.1"
@ -1588,47 +1583,47 @@
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==
"@typescript-eslint/parser@^5.0.0":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.8.1.tgz#380f5f1e596b540059998aa3fc80d78f0f9b0d0a"
integrity sha512-K1giKHAjHuyB421SoXMXFHHVI4NdNY603uKw92++D3qyxSeYvC10CBJ/GE5Thpo4WTUvu1mmJI2/FFkz38F2Gw==
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.9.0.tgz#fdbb08767a4caa6ca6ccfed5f9ffe9387f0c7d97"
integrity sha512-/6pOPz8yAxEt4PLzgbFRDpZmHnXCeZgPDrh/1DaVKOjvn/UPMlWhbx/gA96xRi2JxY1kBl2AmwVbyROUqys5xQ==
dependencies:
"@typescript-eslint/scope-manager" "5.8.1"
"@typescript-eslint/types" "5.8.1"
"@typescript-eslint/typescript-estree" "5.8.1"
"@typescript-eslint/scope-manager" "5.9.0"
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/typescript-estree" "5.9.0"
debug "^4.3.2"
"@typescript-eslint/scope-manager@5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.8.1.tgz#7fc0604f7ade8833e4d42cebaa1e2debf8b932e4"
integrity sha512-DGxJkNyYruFH3NIZc3PwrzwOQAg7vvgsHsHCILOLvUpupgkwDZdNq/cXU3BjF4LNrCsVg0qxEyWasys5AiJ85Q==
"@typescript-eslint/scope-manager@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.9.0.tgz#02dfef920290c1dcd7b1999455a3eaae7a1a3117"
integrity sha512-DKtdIL49Qxk2a8icF6whRk7uThuVz4A6TCXfjdJSwOsf+9ree7vgQWcx0KOyCdk0i9ETX666p4aMhrRhxhUkyg==
dependencies:
"@typescript-eslint/types" "5.8.1"
"@typescript-eslint/visitor-keys" "5.8.1"
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/visitor-keys" "5.9.0"
"@typescript-eslint/types@5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.8.1.tgz#04c6b49ebc8c99238238a6b8b43f2fc613983b5a"
integrity sha512-L/FlWCCgnjKOLefdok90/pqInkomLnAcF9UAzNr+DSqMC3IffzumHTQTrINXhP1gVp9zlHiYYjvozVZDPleLcA==
"@typescript-eslint/types@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.9.0.tgz#e5619803e39d24a03b3369506df196355736e1a3"
integrity sha512-mWp6/b56Umo1rwyGCk8fPIzb9Migo8YOniBGPAQDNC6C52SeyNGN4gsVwQTAR+RS2L5xyajON4hOLwAGwPtUwg==
"@typescript-eslint/typescript-estree@5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.1.tgz#a592855be688e7b729a1e9411d7d74ec992ed6ef"
integrity sha512-26lQ8l8tTbG7ri7xEcCFT9ijU5Fk+sx/KRRyyzCv7MQ+rZZlqiDPtMKWLC8P7o+dtCnby4c+OlxuX1tp8WfafQ==
"@typescript-eslint/typescript-estree@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.9.0.tgz#0e5c6f03f982931abbfbc3c1b9df5fbf92a3490f"
integrity sha512-kxo3xL2mB7XmiVZcECbaDwYCt3qFXz99tBSuVJR4L/sR7CJ+UNAPrYILILktGj1ppfZ/jNt/cWYbziJUlHl1Pw==
dependencies:
"@typescript-eslint/types" "5.8.1"
"@typescript-eslint/visitor-keys" "5.8.1"
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/visitor-keys" "5.9.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/visitor-keys@5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.1.tgz#58a2c566265d5511224bc316149890451c1bbab0"
integrity sha512-SWgiWIwocK6NralrJarPZlWdr0hZnj5GXHIgfdm8hNkyKvpeQuFyLP6YjSIe9kf3YBIfU6OHSZLYkQ+smZwtNg==
"@typescript-eslint/visitor-keys@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.9.0.tgz#7585677732365e9d27f1878150fab3922784a1a6"
integrity sha512-6zq0mb7LV0ThExKlecvpfepiB+XEtFv/bzx7/jKSgyXTFD7qjmSu1FoiS0x3OZaiS+UIXpH2vd9O89f02RCtgw==
dependencies:
"@typescript-eslint/types" "5.8.1"
"@typescript-eslint/types" "5.9.0"
eslint-visitor-keys "^3.0.0"
abort-controller@^3.0.0:
@ -2060,11 +2055,6 @@ character-reference-invalid@^1.0.0:
optionalDependencies:
fsevents "~2.3.2"
classnames@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e"
integrity sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA==
clean-stack@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@ -2444,9 +2434,9 @@ duplexer@^0.1.2:
integrity sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==
electron-to-chromium@^1.4.17:
version "1.4.31"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.31.tgz#8d5ccc3f8253cd142b07afaa84f200fd33a7f2a6"
integrity sha512-t3XVQtk+Frkv6aTD4RRk0OqosU+VLe1dQFW83MDer78ZD6a52frgXuYOIsLYTQiH2Lm+JB2OKYcn7zrX+YGAiQ==
version "1.4.32"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.32.tgz#7ad1e76692b307da454b7380cc882784962648b8"
integrity sha512-7QRVfMlccTFs7cZV3lB0k9Wcm6R6F+w1yBPX+xBAlAP/1oJIstxTev3A4r8REnUUAFph/cIB8y/EBU7PDbJTQw==
emoji-regex@^8.0.0:
version "8.0.0"
@ -2475,7 +2465,7 @@ enquirer@^2.3.5:
dependencies:
ansi-colors "^4.1.1"
entities@^2.0.0, entities@^2.0.3:
entities@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
@ -3298,11 +3288,6 @@ hosted-git-info@^4.0.1:
dependencies:
lru-cache "^6.0.0"
html-entities@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.3.2.tgz#760b404685cb1d794e4f4b744332e3b00dcfe488"
integrity sha512-c3Ab/url5ksaT0WyleslpBEthOzWhrjQbg75y7XUsfSzi3Dgzt0l8w5e7DylRn15MTlMMD58dTfzddNS2kcAjQ==
html-tags@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
@ -4931,14 +4916,6 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"
rss-parser@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/rss-parser/-/rss-parser-3.12.0.tgz#b8888699ea46304a74363fbd8144671b2997984c"
integrity sha512-aqD3E8iavcCdkhVxNDIdg1nkBI17jgqF+9OqPS1orwNaOgySdpvq6B+DoONLhzjzwV8mWg37sb60e4bmLK117A==
dependencies:
entities "^2.0.3"
xml2js "^0.4.19"
run-parallel@^1.1.9:
version "1.2.0"
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
@ -4972,7 +4949,7 @@ sass@^1.45.2:
immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0"
sax@>=0.6.0, sax@^1.2.4:
sax@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
@ -6021,19 +5998,6 @@ xml-js@^1.6.11:
dependencies:
sax "^1.2.4"
xml2js@^0.4.19:
version "0.4.23"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.23.tgz#a0c69516752421eb2ac758ee4d4ccf58843eac66"
integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"
xmlbuilder@~11.0.0:
version "11.0.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"
integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==
xtend@^4.0.0, xtend@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"