X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fclient-html.ts;h=945bc712fe388b5300ad1531161155172ed47ab2;hb=f7ac03ee94d9d32e26bd712e8dc05a6109f5e835;hp=c010f3c441521c0966b0b01d9ff3ed387ac2914d;hpb=d0800f7661f13fabe7bb6f4aa0ea50764f106405;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index c010f3c44..945bc712f 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -1,5 +1,6 @@ import express from 'express' import { readFile } from 'fs-extra' +import memoizee from 'memoizee' import { join } from 'path' import validator from 'validator' import { toCompleteUUID } from '@server/helpers/custom-validators/misc' @@ -20,6 +21,8 @@ import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, FILES_CONTENT_HASH, + MEMOIZE_LENGTH, + MEMOIZE_TTL, PLUGIN_GLOBAL_CSS_PATH, WEBSERVER } from '../initializers/constants' @@ -32,6 +35,11 @@ import { MAccountActor, MChannelActor } from '../types/models' import { getBiggestActorImage } from './actor-image' import { ServerConfigManager } from './server-config-manager' +const getPlainTextDescriptionCached = memoizee(mdToOneLinePlainText, { + maxAge: MEMOIZE_TTL.MD_TO_PLAIN_TEXT_CLIENT_HTML, + max: MEMOIZE_LENGTH.MD_TO_PLAIN_TEXT_CLIENT_HTML +}) + type Tags = { ogType: string twitterCard: 'player' | 'summary' | 'summary_large_image' @@ -104,7 +112,7 @@ class ClientHtml { res.status(HttpStatusCode.NOT_FOUND_404) return html } - const description = mdToOneLinePlainText(video.description) + const description = getPlainTextDescriptionCached(video.description) let customHtml = ClientHtml.addTitleTag(html, video.name) customHtml = ClientHtml.addDescriptionTag(customHtml, description) @@ -165,7 +173,7 @@ class ClientHtml { return html } - const description = mdToOneLinePlainText(videoPlaylist.description) + const description = getPlainTextDescriptionCached(videoPlaylist.description) let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) customHtml = ClientHtml.addDescriptionTag(customHtml, description) @@ -264,7 +272,7 @@ class ClientHtml { return ClientHtml.getIndexHTML(req, res) } - const description = mdToOneLinePlainText(entity.description) + const description = getPlainTextDescriptionCached(entity.description) let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) customHtml = ClientHtml.addDescriptionTag(customHtml, description)