Skip to content

Commit 36346b3

Browse files
committed
improved updates
1 parent 3406f2a commit 36346b3

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

dist/breinify-api.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14131,7 +14131,7 @@ dependencyScope.jQuery = $;;
1413114131
sessionId: null,
1413214132
splitTestData: null,
1413314133

14134-
getSplitTestData: function () {
14134+
getSplitTestData: function (updateChanges) {
1413514135
if ($.isPlainObject(this.splitTestData)) {
1413614136
return this.splitTestData;
1413714137
}
@@ -14148,7 +14148,8 @@ dependencyScope.jQuery = $;;
1414814148
}
1414914149

1415014150
// clean-up old split-test information (older than 7 days)
14151-
var testExpiration = new Date().getTime() - 5 * 60 * 1000;// (7 * 24 * 60 * 1000);
14151+
var testExpiration = new Date().getTime() - (24 * 60 * 60 * 1000);
14152+
var deletedInformation = false;
1415214153
for (var key in this.splitTestData) {
1415314154
if (!this.splitTestData.hasOwnProperty(key)) {
1415414155
continue;
@@ -14157,16 +14158,26 @@ dependencyScope.jQuery = $;;
1415714158
var lastUpdated = this.splitTestData[key].lastUpdated;
1415814159
if (typeof lastUpdated !== 'number' || lastUpdated < testExpiration) {
1415914160
delete this.splitTestData[key];
14161+
deletedInformation = true;
1416014162
}
1416114163
}
1416214164

14165+
if (updateChanges === true && deletedInformation === true) {
14166+
this.updateSplitTestData(this.splitTestData);
14167+
}
14168+
1416314169
return this.splitTestData;
1416414170
},
1416514171

14172+
updateSplitTestData: function(splitTestData) {
14173+
BreinifyUtil.storage.update(BreinifyUtil.storage.splitTestDataInstanceName, 30 * 24 * 60, splitTestData);
14174+
this.splitTestData = splitTestData;
14175+
},
14176+
1416614177
create: function (user) {
1416714178
var splitTestData;
1416814179
try {
14169-
splitTestData = this.getSplitTestData();
14180+
splitTestData = this.getSplitTestData(true);
1417014181
} catch (e) {
1417114182
splitTestData = null;
1417214183
}
@@ -15774,7 +15785,7 @@ dependencyScope.jQuery = $;;
1577415785
}
1577515786

1577615787
// iterate over the additionalData instances and collect the split-test information
15777-
var splitTestData = Breinify.UTL.user.getSplitTestData();
15788+
var splitTestData = Breinify.UTL.user.getSplitTestData(false);
1577815789
if (!$.isPlainObject(splitTestData)) {
1577915790
splitTestData = {};
1578015791
}
@@ -15799,8 +15810,7 @@ dependencyScope.jQuery = $;;
1579915810
* Store the updated information and set it, it can only be modified here -
1580015811
* must be initialized we called `getSplitTestData` previously.
1580115812
*/
15802-
Breinify.UTL.storage.update(BreinifyUtil.storage.splitTestDataInstanceName, 30 * 24 * 60, splitTestData);
15803-
Breinify.UTL.user.splitTestData = splitTestData;
15813+
Breinify.UTL.user.updateSplitTestData(splitTestData);
1580415814
},
1580515815

1580615816
handleRecommendationResponse: function (data, errorText, callback) {
@@ -15809,7 +15819,6 @@ dependencyScope.jQuery = $;;
1580915819
try {
1581015820
this.storeAdditionalData(data);
1581115821
} catch (e) {
15812-
console.log(e);
1581315822
// ignore the exception, we still want to handle the response
1581415823
}
1581515824

dist/breinify-api.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Breinify.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
}
141141

142142
// iterate over the additionalData instances and collect the split-test information
143-
var splitTestData = Breinify.UTL.user.getSplitTestData();
143+
var splitTestData = Breinify.UTL.user.getSplitTestData(false);
144144
if (!$.isPlainObject(splitTestData)) {
145145
splitTestData = {};
146146
}
@@ -165,8 +165,7 @@
165165
* Store the updated information and set it, it can only be modified here -
166166
* must be initialized we called `getSplitTestData` previously.
167167
*/
168-
Breinify.UTL.storage.update(BreinifyUtil.storage.splitTestDataInstanceName, 30 * 24 * 60, splitTestData);
169-
Breinify.UTL.user.splitTestData = splitTestData;
168+
Breinify.UTL.user.updateSplitTestData(splitTestData);
170169
},
171170

172171
handleRecommendationResponse: function (data, errorText, callback) {
@@ -175,7 +174,6 @@
175174
try {
176175
this.storeAdditionalData(data);
177176
} catch (e) {
178-
console.log(e);
179177
// ignore the exception, we still want to handle the response
180178
}
181179

src/BreinifyUtil.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@
764764
sessionId: null,
765765
splitTestData: null,
766766

767-
getSplitTestData: function () {
767+
getSplitTestData: function (updateChanges) {
768768
if ($.isPlainObject(this.splitTestData)) {
769769
return this.splitTestData;
770770
}
@@ -781,7 +781,8 @@
781781
}
782782

783783
// clean-up old split-test information (older than 7 days)
784-
var testExpiration = new Date().getTime() - 5 * 60 * 1000;// (24 * 60 * 60 * 1000);
784+
var testExpiration = new Date().getTime() - (24 * 60 * 60 * 1000);
785+
var deletedInformation = false;
785786
for (var key in this.splitTestData) {
786787
if (!this.splitTestData.hasOwnProperty(key)) {
787788
continue;
@@ -790,16 +791,26 @@
790791
var lastUpdated = this.splitTestData[key].lastUpdated;
791792
if (typeof lastUpdated !== 'number' || lastUpdated < testExpiration) {
792793
delete this.splitTestData[key];
794+
deletedInformation = true;
793795
}
794796
}
795797

798+
if (updateChanges === true && deletedInformation === true) {
799+
this.updateSplitTestData(this.splitTestData);
800+
}
801+
796802
return this.splitTestData;
797803
},
798804

805+
updateSplitTestData: function(splitTestData) {
806+
BreinifyUtil.storage.update(BreinifyUtil.storage.splitTestDataInstanceName, 30 * 24 * 60, splitTestData);
807+
this.splitTestData = splitTestData;
808+
},
809+
799810
create: function (user) {
800811
var splitTestData;
801812
try {
802-
splitTestData = this.getSplitTestData();
813+
splitTestData = this.getSplitTestData(true);
803814
} catch (e) {
804815
splitTestData = null;
805816
}

0 commit comments

Comments
 (0)