Optimizations (#4135)

* removes costly json serialization to InMemoryCacheAdapter

* Always cache a copy of the array

* Use own mapValues

* Makes sure we dont make unnecessary calls to the logger

* Do not bypass loggers with silent logging (only applies to stdout)

* warn is not warning

* use ===

* Wrap logRequest / logResponse in the loggerController for more granular control

Also give the ability to pass functions to the logger so we don't serialize too early in JSON (costly)

* reconfiguring winston would override the transports levels and make subsequent tests fail
This commit is contained in:
Florent Vilmart
2017-09-04 20:47:49 -04:00
committed by GitHub
parent 17f4dcd176
commit 3079270b3e
8 changed files with 118 additions and 33 deletions

View File

@@ -107,7 +107,7 @@ const transformKeyValueForUpdate = (className, restKey, restValue, parseFormatSc
}
// Handle normal objects by recursing
value = _.mapValues(restValue, transformInteriorValue);
value = mapValues(restValue, transformInteriorValue);
return {key, value};
}
@@ -132,7 +132,7 @@ const transformInteriorValue = restValue => {
}
// Handle normal objects by recursing
return _.mapValues(restValue, transformInteriorValue);
return mapValues(restValue, transformInteriorValue);
}
const valueAsDate = value => {
@@ -332,7 +332,7 @@ const parseObjectKeyValueToMongoObjectKeyValue = (restKey, restValue, schema) =>
if (Object.keys(restValue).some(key => key.includes('$') || key.includes('.'))) {
throw new Parse.Error(Parse.Error.INVALID_NESTED_KEY, "Nested keys should not contain the '$' or '.' characters");
}
value = _.mapValues(restValue, transformInteriorValue);
value = mapValues(restValue, transformInteriorValue);
return {key: restKey, value};
}
@@ -789,6 +789,13 @@ function transformUpdateOperator({
throw new Parse.Error(Parse.Error.COMMAND_UNAVAILABLE, `The ${__op} operator is not supported yet.`);
}
}
function mapValues(object, iterator) {
const result = {};
Object.keys(object).forEach((key) => {
result[key] = iterator(object[key]);
});
return result;
}
const nestedMongoObjectToNestedParseObject = mongoObject => {
switch(typeof mongoObject) {
@@ -829,7 +836,7 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
return mongoObject;
}
return _.mapValues(mongoObject, nestedMongoObjectToNestedParseObject);
return mapValues(mongoObject, nestedMongoObjectToNestedParseObject);
default:
throw 'unknown js type';
}