Fix client html performance regression
This commit is contained in:
parent
70a8e50a5d
commit
f7ac03ee94
3 changed files with 16 additions and 6 deletions
|
@ -8,7 +8,7 @@ const markdownItEmoji = require('markdown-it-emoji/light')
|
||||||
const MarkdownItClass = require('markdown-it')
|
const MarkdownItClass = require('markdown-it')
|
||||||
|
|
||||||
const markdownItWithHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: true })
|
const markdownItWithHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: true })
|
||||||
const markdownItWithoutHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: false })
|
const markdownItWithoutHTML = new MarkdownItClass('default', { linkify: false, breaks: true, html: false })
|
||||||
|
|
||||||
const toSafeHtml = (text: string) => {
|
const toSafeHtml = (text: string) => {
|
||||||
if (!text) return ''
|
if (!text) return ''
|
||||||
|
@ -66,7 +66,7 @@ function plainTextPlugin (markdownIt: any) {
|
||||||
|
|
||||||
if (token.type === 'list_item_close') {
|
if (token.type === 'list_item_close') {
|
||||||
lastSeparator = ', '
|
lastSeparator = ', '
|
||||||
} else if (/[a-zA-Z]+_close/.test(token.type)) {
|
} else if (token.type.endsWith('_close')) {
|
||||||
lastSeparator = ' '
|
lastSeparator = ' '
|
||||||
} else if (token.content) {
|
} else if (token.content) {
|
||||||
text += lastSeparator
|
text += lastSeparator
|
||||||
|
|
|
@ -718,10 +718,12 @@ const MEMOIZE_TTL = {
|
||||||
OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
|
OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
|
||||||
INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
|
INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
|
||||||
LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
|
LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
|
||||||
LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute
|
LIVE_CHECK_SOCKET_HEALTH: 1000 * 60, // 1 minute
|
||||||
|
MD_TO_PLAIN_TEXT_CLIENT_HTML: 1000 * 60 // 1 minute
|
||||||
}
|
}
|
||||||
|
|
||||||
const MEMOIZE_LENGTH = {
|
const MEMOIZE_LENGTH = {
|
||||||
|
MD_TO_PLAIN_TEXT_CLIENT_HTML: 100,
|
||||||
INFO_HASH_EXISTS: 200
|
INFO_HASH_EXISTS: 200
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { readFile } from 'fs-extra'
|
import { readFile } from 'fs-extra'
|
||||||
|
import memoizee from 'memoizee'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { toCompleteUUID } from '@server/helpers/custom-validators/misc'
|
import { toCompleteUUID } from '@server/helpers/custom-validators/misc'
|
||||||
|
@ -20,6 +21,8 @@ import {
|
||||||
CUSTOM_HTML_TAG_COMMENTS,
|
CUSTOM_HTML_TAG_COMMENTS,
|
||||||
EMBED_SIZE,
|
EMBED_SIZE,
|
||||||
FILES_CONTENT_HASH,
|
FILES_CONTENT_HASH,
|
||||||
|
MEMOIZE_LENGTH,
|
||||||
|
MEMOIZE_TTL,
|
||||||
PLUGIN_GLOBAL_CSS_PATH,
|
PLUGIN_GLOBAL_CSS_PATH,
|
||||||
WEBSERVER
|
WEBSERVER
|
||||||
} from '../initializers/constants'
|
} from '../initializers/constants'
|
||||||
|
@ -32,6 +35,11 @@ import { MAccountActor, MChannelActor } from '../types/models'
|
||||||
import { getBiggestActorImage } from './actor-image'
|
import { getBiggestActorImage } from './actor-image'
|
||||||
import { ServerConfigManager } from './server-config-manager'
|
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 = {
|
type Tags = {
|
||||||
ogType: string
|
ogType: string
|
||||||
twitterCard: 'player' | 'summary' | 'summary_large_image'
|
twitterCard: 'player' | 'summary' | 'summary_large_image'
|
||||||
|
@ -104,7 +112,7 @@ class ClientHtml {
|
||||||
res.status(HttpStatusCode.NOT_FOUND_404)
|
res.status(HttpStatusCode.NOT_FOUND_404)
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
const description = mdToOneLinePlainText(video.description)
|
const description = getPlainTextDescriptionCached(video.description)
|
||||||
|
|
||||||
let customHtml = ClientHtml.addTitleTag(html, video.name)
|
let customHtml = ClientHtml.addTitleTag(html, video.name)
|
||||||
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
||||||
|
@ -165,7 +173,7 @@ class ClientHtml {
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = mdToOneLinePlainText(videoPlaylist.description)
|
const description = getPlainTextDescriptionCached(videoPlaylist.description)
|
||||||
|
|
||||||
let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name)
|
let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name)
|
||||||
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
||||||
|
@ -264,7 +272,7 @@ class ClientHtml {
|
||||||
return ClientHtml.getIndexHTML(req, res)
|
return ClientHtml.getIndexHTML(req, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = mdToOneLinePlainText(entity.description)
|
const description = getPlainTextDescriptionCached(entity.description)
|
||||||
|
|
||||||
let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName())
|
let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName())
|
||||||
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
customHtml = ClientHtml.addDescriptionTag(customHtml, description)
|
||||||
|
|
Loading…
Add table
Reference in a new issue