mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 02:09:37 +02:00
Remove async-lru cache for jsonld
jsonld library has already a cache
This commit is contained in:
parent
a5bdce80f6
commit
c900788e59
4 changed files with 10 additions and 37 deletions
|
@ -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 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue