Skip to content

Commit 89d006a

Browse files
feat: caching of customs with predefineds
1 parent aed4a42 commit 89d006a

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

lib/countly.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -836,24 +836,31 @@ Countly.Bulk = Bulk;
836836
* @param {Object=} user.custom - object with custom key value properties you want to save with user
837837
* */
838838
Countly.user_details = function(user) {
839-
cc.log(cc.logLevelEnums.INFO, "user_details, Adding user details: ", user);
839+
Countly.userProfile.set_properties(user);
840+
Countly.userProfile.save();
841+
};
842+
843+
var change_custom_property = function(key, value, mod) {
844+
key = cc.truncateSingleValue(key, Countly.maxKeyLength, "change_custom_property", Countly.debug);
845+
value = cc.truncateSingleValue(value, Countly.maxValueSize, "change_custom_property", Countly.debug);
846+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
847+
cc.log(cc.logLevelEnums.ERROR, "change_custom_property, Provided key is not allowed.");
848+
return;
849+
}
850+
840851
if (Countly.check_consent("users")) {
841-
var props = ["name", "username", "email", "organization", "phone", "picture", "gender", "byear", "custom"];
842-
user.name = cc.truncateSingleValue(user.name, Countly.maxValueSize, "user_details", Countly.debug);
843-
user.username = cc.truncateSingleValue(user.username, Countly.maxValueSize, "user_details", Countly.debug);
844-
user.email = cc.truncateSingleValue(user.email, Countly.maxValueSize, "user_details", Countly.debug);
845-
user.organization = cc.truncateSingleValue(user.organization, Countly.maxValueSize, "user_details", Countly.debug);
846-
user.phone = cc.truncateSingleValue(user.phone, Countly.maxValueSize, "user_details", Countly.debug);
847-
user.picture = cc.truncateSingleValue(user.picture, 4096, "user_details", Countly.debug);
848-
user.gender = cc.truncateSingleValue(user.gender, Countly.maxValueSize, "user_details", Countly.debug);
849-
user.byear = cc.truncateSingleValue(user.byear, Countly.maxValueSize, "user_details", Countly.debug);
850-
user.custom = cc.truncateObject(user.custom, Countly.maxKeyLength, Countly.maxValueSize, Countly.maxSegmentationValues, "user_details");
851-
var request = { user_details: JSON.stringify(cc.getProperties(user, props)) };
852-
if (!user.picture && user.picturePath) {
853-
cc.log(cc.logLevelEnums.INFO, "user_details, Picture is not set but picturePath is set, will try to upload picture from path.");
854-
request.picturePath = user.picturePath;
855-
}
856-
toRequestQueue(request);
852+
if (!userProperties.custom[key]) {
853+
userProperties.custom[key] = {};
854+
}
855+
if (mod === "$push" || mod === "$pull" || mod === "$addToSet") {
856+
if (!userProperties.custom[key][mod]) {
857+
userProperties.custom[key][mod] = [];
858+
}
859+
userProperties.custom[key][mod].push(value);
860+
}
861+
else {
862+
userProperties.custom[key][mod] = value;
863+
}
857864
}
858865
};
859866

0 commit comments

Comments
 (0)