From fc082152780b1a3f5b06a8ab873cdd265314211d Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Wed, 15 Dec 2021 11:21:03 -0800 Subject: [PATCH 1/2] In memory cache api pages (#23751) --- middleware/render-page.js | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/middleware/render-page.js b/middleware/render-page.js index a082920d6a..149417ba18 100644 --- a/middleware/render-page.js +++ b/middleware/render-page.js @@ -5,6 +5,8 @@ import Page from '../lib/page.js' import { isConnectionDropped } from './halt-on-dropped-connection.js' import { nextApp, nextHandleRequest } from './next.js' +const pageCache = new Map() + export default async function renderPage(req, res, next) { if (req.path.startsWith('/storybook')) { return nextHandleRequest(req, res) @@ -29,6 +31,45 @@ export default async function renderPage(req, res, next) { // Is the request for JSON debugging info? const isRequestingJsonForDebugging = 'json' in req.query && process.env.NODE_ENV !== 'production' + // ****** temporary caching measure for holiday spam prevention ********* + + const isApiPage = + req.context.currentPathWithoutLanguage.includes('rest/reference') || + req.context.currentPathWithoutLanguage.includes('graphql/reference') + + // Serve from the cache if possible + const isCacheable = + // Skip for CI + !process.env.CI && + // Skip for tests + process.env.NODE_ENV !== 'test' && + // Skip for HTTP methods other than GET + req.method === 'GET' && + // Skip for JSON debugging info requests + !isRequestingJsonForDebugging && + // Only API pages + isApiPage + + // don't cache query strings + const originalUrl = req.originalUrl.split('?')[0] + + if (isCacheable) { + // Stop processing if the connection was already dropped + if (isConnectionDropped(req, res)) return + + const cachedHtml = pageCache.get(originalUrl) + if (cachedHtml) { + // Stop processing if the connection was already dropped + if (isConnectionDropped(req, res)) return + + console.log(`Serving from cached version of ${originalUrl}`) + // statsd.increment('page.sent_from_cache') + return res.send(cachedHtml) + } + } + + // ****** [end] temporary caching measure for holiday spam prevention ********* + // add page context const context = Object.assign({}, req.context, { page }) @@ -104,5 +145,12 @@ export default async function renderPage(req, res, next) { // Hand rendering over to NextJS req.context.renderedPage = context.renderedPage req.context.miniTocItems = context.miniTocItems + + // ****** temporary caching measure for holiday spam prevention ********* + if (isCacheable) { + pageCache.set(originalUrl, req.context.renderedPage) + } + // ****** [end] temporary caching measure for holiday spam prevention ********* + return nextHandleRequest(req, res) } From 0c0e0daf8eefdd246cff70c7cbe8f792d0d30e9c Mon Sep 17 00:00:00 2001 From: docubot <67483024+docubot@users.noreply.github.com> Date: Wed, 15 Dec 2021 13:24:42 -0600 Subject: [PATCH 2/2] New translation batch for cn (#23717) * Add crowdin translations * Run script/i18n/homogenize-frontmatter.js * Run script/i18n/lint-translation-files.js --check parsing * Run script/i18n/lint-translation-files.js --check rendering * run script/i18n/reset-files-with-broken-liquid-tags.js --language=cn * run script/i18n/reset-known-broken-translation-files.js * Check in cn CSV report