1
0
Fork 0

Remove async-lru cache for jsonld

jsonld library has already a cache
This commit is contained in:
Chocobozzz 2023-11-28 17:35:28 +01:00
parent a5bdce80f6
commit c900788e59
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 10 additions and 37 deletions

View File

@ -109,7 +109,6 @@
"@peertube/http-signature": "^1.7.0",
"@smithy/node-http-handler": "^2.1.7",
"@uploadx/core": "^6.0.0",
"async-lru": "^1.1.1",
"async-mutex": "^0.4.0",
"bcrypt": "5.1.1",
"bencode": "^4.0.0",

View File

@ -1,6 +1,4 @@
import AsyncLRU from 'async-lru'
import jsonld from 'jsonld'
import { logger } from './logger.js'
const CACHE = {
'https://w3id.org/security/v1': {
@ -55,36 +53,19 @@ const CACHE = {
}
}
const nodeDocumentLoader = (jsonld as any).documentLoaders.node()
const lru = new AsyncLRU({
max: 10,
load: (url, cb) => {
if (CACHE[url] !== undefined) {
logger.debug('Using cache for JSON-LD %s.', url)
return cb(null, {
contextUrl: null,
document: CACHE[url],
documentUrl: url
})
}
nodeDocumentLoader(url)
.then(value => cb(null, value))
.catch(err => cb(err))
}
});
const nodeDocumentLoader = (jsonld as any).documentLoaders.node();
/* eslint-disable no-import-assign */
(jsonld as any).documentLoader = (url) => {
return new Promise((res, rej) => {
lru.get(url, (err, value) => {
if (err) return rej(err)
return res(value)
if (url in CACHE) {
return Promise.resolve({
contextUrl: null,
document: CACHE[url],
documentUrl: url
})
})
}
return nodeDocumentLoader(url)
}
export { jsonld }

View File

@ -988,7 +988,7 @@ const WORKER_THREADS = {
},
BUILD_DIGEST: {
CONCURRENCY: 1,
MAX_THREADS: Math.min(totalCPUs, 2)
MAX_THREADS: 1
}
}

View File

@ -3199,13 +3199,6 @@ assertion-error@^1.1.0:
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==
async-lru@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/async-lru/-/async-lru-1.1.3.tgz#38f1a99379d4872d969136858be098ca2550f4c6"
integrity sha512-tPoYtjE2HCZqZHgOqFJLbgLP+IzY0V1qldIvH/lYd2opuMtO9OURxaCgNBhy5m4lUs3mz4R5iG+xI2uuqoOlwQ==
dependencies:
lru "^3.1.0"
async-mutex@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.4.0.tgz#ae8048cd4d04ace94347507504b3cf15e631c25f"