Taking into account persist property
The "persist" property was not taken into account and all variables were stored in DB. This change makes sure only variables tagged with "persist" are actually persisted.
This commit is contained in:
parent
2aba6b1c27
commit
88f2bfdf39
1 changed files with 20 additions and 4 deletions
|
@ -51,6 +51,17 @@ export class VariablesManager {
|
||||||
}
|
}
|
||||||
const variables = await variablesRepository.loadVariables(this.roomUrl);
|
const variables = await variablesRepository.loadVariables(this.roomUrl);
|
||||||
for (const key in variables) {
|
for (const key in variables) {
|
||||||
|
// Let's only set variables if they are in the map (if the map has changed, maybe stored variables do not exist anymore)
|
||||||
|
if (this.variableObjects) {
|
||||||
|
const variableObject = this.variableObjects.get(key);
|
||||||
|
if (variableObject === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!variableObject.persist) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._variables.set(key, variables[key]);
|
this._variables.set(key, variables[key]);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -146,8 +157,9 @@ export class VariablesManager {
|
||||||
*/
|
*/
|
||||||
setVariable(name: string, value: string, user: User): string | undefined | false {
|
setVariable(name: string, value: string, user: User): string | undefined | false {
|
||||||
let readableBy: string | undefined;
|
let readableBy: string | undefined;
|
||||||
|
let variableObject: Variable | undefined;
|
||||||
if (this.variableObjects) {
|
if (this.variableObjects) {
|
||||||
const variableObject = this.variableObjects.get(name);
|
variableObject = this.variableObjects.get(name);
|
||||||
if (variableObject === undefined) {
|
if (variableObject === undefined) {
|
||||||
throw new Error('Trying to set a variable "' + name + '" that is not defined as an object in the map.');
|
throw new Error('Trying to set a variable "' + name + '" that is not defined as an object in the map.');
|
||||||
}
|
}
|
||||||
|
@ -175,9 +187,13 @@ export class VariablesManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._variables.set(name, value);
|
this._variables.set(name, value);
|
||||||
variablesRepository
|
|
||||||
.saveVariable(this.roomUrl, name, value)
|
if (variableObject !== undefined && variableObject.persist) {
|
||||||
.catch((e) => console.error("Error while saving variable in Redis:", e));
|
variablesRepository
|
||||||
|
.saveVariable(this.roomUrl, name, value)
|
||||||
|
.catch((e) => console.error("Error while saving variable in Redis:", e));
|
||||||
|
}
|
||||||
|
|
||||||
return readableBy;
|
return readableBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue