Skip to content

Commit 13de5cb

Browse files
author
Max Presman
committed
deduping operations
1 parent e9b8fee commit 13de5cb

File tree

13 files changed

+278
-31
lines changed

13 files changed

+278
-31
lines changed

dist/titanium/pubnub.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ return /******/ (function(modules) { // webpackBootstrap
663663
this.keepAliveSettings = setup.keepAliveSettings;
664664
this.autoNetworkDetection = setup.autoNetworkDetection || false;
665665

666+
this.dedupeOnSubscribe = setup.dedupeOnSubscribe || false;
667+
this.maximumCacheSize = setup.maximumCacheSize || 100;
668+
666669
this.customEncrypt = setup.customEncrypt;
667670
this.customDecrypt = setup.customDecrypt;
668671

@@ -1469,9 +1472,9 @@ return /******/ (function(modules) { // webpackBootstrap
14691472

14701473
var _cryptography2 = _interopRequireDefault(_cryptography);
14711474

1472-
var _config = __webpack_require__(7);
1475+
var _config2 = __webpack_require__(7);
14731476

1474-
var _config2 = _interopRequireDefault(_config);
1477+
var _config3 = _interopRequireDefault(_config2);
14751478

14761479
var _listener_manager = __webpack_require__(12);
14771480

@@ -1868,7 +1871,9 @@ return /******/ (function(modules) { // webpackBootstrap
18681871
}
18691872

18701873
var messages = payload.messages || [];
1871-
var requestMessageCountThreshold = this._config.requestMessageCountThreshold;
1874+
var _config = this._config,
1875+
requestMessageCountThreshold = _config.requestMessageCountThreshold,
1876+
dedupeOnSubscribe = _config.dedupeOnSubscribe;
18721877

18731878

18741879
if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) {
@@ -1887,7 +1892,13 @@ return /******/ (function(modules) { // webpackBootstrap
18871892
subscriptionMatch = null;
18881893
}
18891894

1890-
_this5._dedupingManager.isDuplicate(message);
1895+
if (dedupeOnSubscribe) {
1896+
if (_this5._dedupingManager.isDuplicate(message)) {
1897+
return;
1898+
} else {
1899+
_this5._dedupingManager.addEntry(message);
1900+
}
1901+
}
18911902

18921903
if (_utils2.default.endsWith(message.channel, '-pnpres')) {
18931904
var announce = {};
@@ -2304,17 +2315,21 @@ return /******/ (function(modules) { // webpackBootstrap
23042315
key: 'getKey',
23052316
value: function getKey(message) {
23062317
var hashedPayload = hashCode(JSON.stringify(message.payload)).toString();
2307-
return message.channel + '-' + hashedPayload;
2318+
var timetoken = message.publishMetaData.publishTimetoken;
2319+
return timetoken + '-' + hashedPayload;
23082320
}
23092321
}, {
23102322
key: 'isDuplicate',
23112323
value: function isDuplicate(message) {
2312-
console.log('getKey', this.getKey(message));
23132324
return this.hashHistory.includes(this.getKey(message));
23142325
}
23152326
}, {
23162327
key: 'addEntry',
23172328
value: function addEntry(message) {
2329+
if (this.hashHistory.length >= this._config.maximumCacheSize) {
2330+
this.hashHistory.shift();
2331+
}
2332+
23182333
this.hashHistory.push(this.getKey(message));
23192334
}
23202335
}, {

dist/titanium/pubnub.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web/pubnub.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@ return /******/ (function(modules) { // webpackBootstrap
685685
this.keepAliveSettings = setup.keepAliveSettings;
686686
this.autoNetworkDetection = setup.autoNetworkDetection || false;
687687

688+
this.dedupeOnSubscribe = setup.dedupeOnSubscribe || false;
689+
this.maximumCacheSize = setup.maximumCacheSize || 100;
690+
688691
this.customEncrypt = setup.customEncrypt;
689692
this.customDecrypt = setup.customDecrypt;
690693

@@ -1491,9 +1494,9 @@ return /******/ (function(modules) { // webpackBootstrap
14911494

14921495
var _cryptography2 = _interopRequireDefault(_cryptography);
14931496

1494-
var _config = __webpack_require__(7);
1497+
var _config2 = __webpack_require__(7);
14951498

1496-
var _config2 = _interopRequireDefault(_config);
1499+
var _config3 = _interopRequireDefault(_config2);
14971500

14981501
var _listener_manager = __webpack_require__(12);
14991502

@@ -1890,7 +1893,9 @@ return /******/ (function(modules) { // webpackBootstrap
18901893
}
18911894

18921895
var messages = payload.messages || [];
1893-
var requestMessageCountThreshold = this._config.requestMessageCountThreshold;
1896+
var _config = this._config,
1897+
requestMessageCountThreshold = _config.requestMessageCountThreshold,
1898+
dedupeOnSubscribe = _config.dedupeOnSubscribe;
18941899

18951900

18961901
if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) {
@@ -1909,7 +1914,13 @@ return /******/ (function(modules) { // webpackBootstrap
19091914
subscriptionMatch = null;
19101915
}
19111916

1912-
_this5._dedupingManager.isDuplicate(message);
1917+
if (dedupeOnSubscribe) {
1918+
if (_this5._dedupingManager.isDuplicate(message)) {
1919+
return;
1920+
} else {
1921+
_this5._dedupingManager.addEntry(message);
1922+
}
1923+
}
19131924

19141925
if (_utils2.default.endsWith(message.channel, '-pnpres')) {
19151926
var announce = {};
@@ -2326,17 +2337,21 @@ return /******/ (function(modules) { // webpackBootstrap
23262337
key: 'getKey',
23272338
value: function getKey(message) {
23282339
var hashedPayload = hashCode(JSON.stringify(message.payload)).toString();
2329-
return message.channel + '-' + hashedPayload;
2340+
var timetoken = message.publishMetaData.publishTimetoken;
2341+
return timetoken + '-' + hashedPayload;
23302342
}
23312343
}, {
23322344
key: 'isDuplicate',
23332345
value: function isDuplicate(message) {
2334-
console.log('getKey', this.getKey(message));
23352346
return this.hashHistory.includes(this.getKey(message));
23362347
}
23372348
}, {
23382349
key: 'addEntry',
23392350
value: function addEntry(message) {
2351+
if (this.hashHistory.length >= this._config.maximumCacheSize) {
2352+
this.hashHistory.shift();
2353+
}
2354+
23402355
this.hashHistory.push(this.getKey(message));
23412356
}
23422357
}, {

dist/web/pubnub.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/config.js.map

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

lib/core/components/deduping_manager.js

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/deduping_manager.js.map

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

lib/core/components/subscription_manager.js

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/subscription_manager.js.map

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

0 commit comments

Comments
 (0)