diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-08 11:34:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-08 11:39:56 +0100 |
commit | cc45cc9ac1d0afbe4844c34b13dd4a65dd523be1 (patch) | |
tree | 11417242ae9f6d359fb68a92214fc8565b3b44d2 | |
parent | 7b51ede977c299a74728171d8c124bcc4cbba6ea (diff) | |
download | PeerTube-cc45cc9ac1d0afbe4844c34b13dd4a65dd523be1.tar.gz PeerTube-cc45cc9ac1d0afbe4844c34b13dd4a65dd523be1.tar.zst PeerTube-cc45cc9ac1d0afbe4844c34b13dd4a65dd523be1.zip |
Remove uneeded memoize
-rw-r--r-- | scripts/benchmark.ts | 2 | ||||
-rw-r--r-- | server/initializers/constants.ts | 4 | ||||
-rw-r--r-- | server/lib/client-html.ts | 16 |
3 files changed, 6 insertions, 16 deletions
diff --git a/scripts/benchmark.ts b/scripts/benchmark.ts index c9486eb37..48e740dff 100644 --- a/scripts/benchmark.ts +++ b/scripts/benchmark.ts | |||
@@ -215,7 +215,7 @@ async function prepare () { | |||
215 | language: 'fr', | 215 | language: 'fr', |
216 | privacy: VideoPrivacy.PUBLIC, | 216 | privacy: VideoPrivacy.PUBLIC, |
217 | support: 'please give me a coffee', | 217 | support: 'please give me a coffee', |
218 | description: 'my super description'.repeat(10), | 218 | description: 'my super description\n'.repeat(10) + ' * list1\n * list 2\n * list 3', |
219 | tags: [ 'tag1', 'tag2', 'tag3' ] | 219 | tags: [ 'tag1', 'tag2', 'tag3' ] |
220 | } | 220 | } |
221 | 221 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 3069e2353..7bc2877aa 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -718,12 +718,10 @@ const MEMOIZE_TTL = { | |||
718 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours | 718 | OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours |
719 | INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours | 719 | INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours |
720 | LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute | 720 | LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute |
721 | LIVE_CHECK_SOCKET_HEALTH: 1000 * 60, // 1 minute | 721 | LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute |
722 | MD_TO_PLAIN_TEXT_CLIENT_HTML: 1000 * 60 // 1 minute | ||
723 | } | 722 | } |
724 | 723 | ||
725 | const MEMOIZE_LENGTH = { | 724 | const MEMOIZE_LENGTH = { |
726 | MD_TO_PLAIN_TEXT_CLIENT_HTML: 100, | ||
727 | INFO_HASH_EXISTS: 200 | 725 | INFO_HASH_EXISTS: 200 |
728 | } | 726 | } |
729 | 727 | ||
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 945bc712f..0142b248b 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { readFile } from 'fs-extra' | 2 | import { readFile } from 'fs-extra' |
3 | import memoizee from 'memoizee' | ||
4 | import { join } from 'path' | 3 | import { join } from 'path' |
5 | import validator from 'validator' | 4 | import validator from 'validator' |
6 | import { toCompleteUUID } from '@server/helpers/custom-validators/misc' | 5 | import { toCompleteUUID } from '@server/helpers/custom-validators/misc' |
6 | import { mdToOneLinePlainText } from '@server/helpers/markdown' | ||
7 | import { ActorImageModel } from '@server/models/actor/actor-image' | 7 | import { ActorImageModel } from '@server/models/actor/actor-image' |
8 | import { root } from '@shared/core-utils' | 8 | import { root } from '@shared/core-utils' |
9 | import { escapeHTML } from '@shared/core-utils/renderer' | 9 | import { escapeHTML } from '@shared/core-utils/renderer' |
@@ -14,15 +14,12 @@ import { HttpStatusCode } from '../../shared/models/http/http-error-codes' | |||
14 | import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' | 14 | import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' |
15 | import { isTestInstance } from '../helpers/core-utils' | 15 | import { isTestInstance } from '../helpers/core-utils' |
16 | import { logger } from '../helpers/logger' | 16 | import { logger } from '../helpers/logger' |
17 | import { mdToOneLinePlainText } from '../helpers/markdown' | ||
18 | import { CONFIG } from '../initializers/config' | 17 | import { CONFIG } from '../initializers/config' |
19 | import { | 18 | import { |
20 | ACCEPT_HEADERS, | 19 | ACCEPT_HEADERS, |
21 | CUSTOM_HTML_TAG_COMMENTS, | 20 | CUSTOM_HTML_TAG_COMMENTS, |
22 | EMBED_SIZE, | 21 | EMBED_SIZE, |
23 | FILES_CONTENT_HASH, | 22 | FILES_CONTENT_HASH, |
24 | MEMOIZE_LENGTH, | ||
25 | MEMOIZE_TTL, | ||
26 | PLUGIN_GLOBAL_CSS_PATH, | 23 | PLUGIN_GLOBAL_CSS_PATH, |
27 | WEBSERVER | 24 | WEBSERVER |
28 | } from '../initializers/constants' | 25 | } from '../initializers/constants' |
@@ -35,11 +32,6 @@ import { MAccountActor, MChannelActor } from '../types/models' | |||
35 | import { getBiggestActorImage } from './actor-image' | 32 | import { getBiggestActorImage } from './actor-image' |
36 | import { ServerConfigManager } from './server-config-manager' | 33 | import { ServerConfigManager } from './server-config-manager' |
37 | 34 | ||
38 | const getPlainTextDescriptionCached = memoizee(mdToOneLinePlainText, { | ||
39 | maxAge: MEMOIZE_TTL.MD_TO_PLAIN_TEXT_CLIENT_HTML, | ||
40 | max: MEMOIZE_LENGTH.MD_TO_PLAIN_TEXT_CLIENT_HTML | ||
41 | }) | ||
42 | |||
43 | type Tags = { | 35 | type Tags = { |
44 | ogType: string | 36 | ogType: string |
45 | twitterCard: 'player' | 'summary' | 'summary_large_image' | 37 | twitterCard: 'player' | 'summary' | 'summary_large_image' |
@@ -112,7 +104,7 @@ class ClientHtml { | |||
112 | res.status(HttpStatusCode.NOT_FOUND_404) | 104 | res.status(HttpStatusCode.NOT_FOUND_404) |
113 | return html | 105 | return html |
114 | } | 106 | } |
115 | const description = getPlainTextDescriptionCached(video.description) | 107 | const description = mdToOneLinePlainText(video.description) |
116 | 108 | ||
117 | let customHtml = ClientHtml.addTitleTag(html, video.name) | 109 | let customHtml = ClientHtml.addTitleTag(html, video.name) |
118 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 110 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |
@@ -173,7 +165,7 @@ class ClientHtml { | |||
173 | return html | 165 | return html |
174 | } | 166 | } |
175 | 167 | ||
176 | const description = getPlainTextDescriptionCached(videoPlaylist.description) | 168 | const description = mdToOneLinePlainText(videoPlaylist.description) |
177 | 169 | ||
178 | let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) | 170 | let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) |
179 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 171 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |
@@ -272,7 +264,7 @@ class ClientHtml { | |||
272 | return ClientHtml.getIndexHTML(req, res) | 264 | return ClientHtml.getIndexHTML(req, res) |
273 | } | 265 | } |
274 | 266 | ||
275 | const description = getPlainTextDescriptionCached(entity.description) | 267 | const description = mdToOneLinePlainText(entity.description) |
276 | 268 | ||
277 | let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) | 269 | let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) |
278 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 270 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |