feat: throttling configuration

This commit is contained in:
Florent Chehab
2020-05-11 14:12:20 +02:00
parent 409681b217
commit ca47c41c69
8 changed files with 134 additions and 40 deletions

View File

@@ -41,20 +41,28 @@
"performance": {
"type": "object",
"additionalProperties": false,
"required": ["pointerEventsThreshold", "refreshInfoFreq"],
"required": ["pointerEventsThrottling", "refreshInfoFreq"],
"properties": {
"pointerEventsThreshold": {
"type": "object",
"additionalProperties": false,
"required": ["minDistDelta", "minTimeDelta"],
"properties": {
"minDistDelta": {
"type": "number",
"minimum": 0
},
"minTimeDelta": {
"type": "number",
"minimum": 0
"pointerEventsThrottling": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["fromNbUser", "minDistDelta", "maxFreq"],
"properties": {
"fromNbUser": {
"type": "number",
"minimum": 0
},
"minDistDelta": {
"type": "number",
"minimum": 0
},
"maxFreq": {
"type": "number",
"minimum": 0
}
}
}
},

View File

@@ -44,11 +44,28 @@ function getConfig(path) {
*/
function isConfigValid(config, warn = true) {
const validate = ajv.compile(configSchema);
const isValid = validate(config);
const isValidAgainstSchema = validate(config);
if (!isValid && warn) console.warn(validate.errors);
if (!isValidAgainstSchema && warn) console.warn(validate.errors);
return isValid;
let structureIsValid = false;
try {
structureIsValid = config.frontend.performance.pointerEventsThrottling.some(
(item) => item.fromNbUser === 0
);
} catch (e) {
if (!e instanceof TypeError) {
throw e;
}
}
if (!structureIsValid && warn)
console.warn(
"At least one item under frontend.performance.pointerEventsThrottling" +
"must have fromNbUser set to 0"
);
return isValidAgainstSchema && structureIsValid;
}
/**