ajv-validator / ajv-validator/ajv

Let users configure Cache to use for compiled schemas

Abierto
#2,134 4 comentarios 1 reacción 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
TypeScript
Estrellas
14.8k
Forks
1k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**What version of Ajv you are you using?**
8.11.0

**What problem do you want to solve?**
If `compile` function called with same by-value, but not by-ref object, it can cause cache overflow and memory leakage.
```
const getSchema = () => ({ type: 'object' });
const schema1 = getSchema();
const schema2 = getSchema();
console.log('schemas are equal by-ref? ', schema1 === schema2);

// caching is not actually works down here
// Map is growing, nothing cleans it
ajv.compile(schema1);
ajv.compile(schema2);
ajv.compile(getSchema());
...
ajv.compile(getSchema());
```

**What do you think is the correct solution to problem?**
Implement WeakMap instead of Map class.

**Will you be able to implement it?**
I'll attach the pull request.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.