Remove uneeded memoize

This commit is contained in:
Chocobozzz 2022-03-08 11:34:15 +01:00
parent 7b51ede977
commit cc45cc9ac1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 6 additions and 16 deletions

View File

@ -215,7 +215,7 @@ async function prepare () {
language: 'fr', language: 'fr',
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
support: 'please give me a coffee', support: 'please give me a coffee',
description: 'my super description'.repeat(10), description: 'my super description\n'.repeat(10) + ' * list1\n * list 2\n * list 3',
tags: [ 'tag1', 'tag2', 'tag3' ] tags: [ 'tag1', 'tag2', 'tag3' ]
} }

View File

@ -718,12 +718,10 @@ 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
} }

View File

@ -1,9 +1,9 @@
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'
import { mdToOneLinePlainText } from '@server/helpers/markdown'
import { ActorImageModel } from '@server/models/actor/actor-image' import { ActorImageModel } from '@server/models/actor/actor-image'
import { root } from '@shared/core-utils' import { root } from '@shared/core-utils'
import { escapeHTML } from '@shared/core-utils/renderer' import { escapeHTML } from '@shared/core-utils/renderer'
@ -14,15 +14,12 @@ import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos'
import { isTestInstance } from '../helpers/core-utils' import { isTestInstance } from '../helpers/core-utils'
import { logger } from '../helpers/logger' import { logger } from '../helpers/logger'
import { mdToOneLinePlainText } from '../helpers/markdown'
import { CONFIG } from '../initializers/config' import { CONFIG } from '../initializers/config'
import { import {
ACCEPT_HEADERS, ACCEPT_HEADERS,
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'
@ -35,11 +32,6 @@ 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'
@ -112,7 +104,7 @@ class ClientHtml {
res.status(HttpStatusCode.NOT_FOUND_404) res.status(HttpStatusCode.NOT_FOUND_404)
return html return html
} }
const description = getPlainTextDescriptionCached(video.description) const description = mdToOneLinePlainText(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)
@ -173,7 +165,7 @@ class ClientHtml {
return html return html
} }
const description = getPlainTextDescriptionCached(videoPlaylist.description) const description = mdToOneLinePlainText(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)
@ -272,7 +264,7 @@ class ClientHtml {
return ClientHtml.getIndexHTML(req, res) return ClientHtml.getIndexHTML(req, res)
} }
const description = getPlainTextDescriptionCached(entity.description) const description = mdToOneLinePlainText(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)