Skip to content

Commit

Permalink
Process a lot less nodes, and use a lock to ensure we don't over exer…
Browse files Browse the repository at this point in the history
…t ourselves.

Part of #73
  • Loading branch information
turt2live committed Apr 13, 2017
1 parent 3eb339c commit e2695a9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/VoyagerBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class VoyagerBot {
var mtxStore = new VoyagerMatrixStore(localStorage);

this._nodeUpdateQueue = [];
this._processingNodes = false;

this._store = store;
this._commandProcessor = new CommandProcessor(this, store);

Expand Down Expand Up @@ -404,7 +406,13 @@ class VoyagerBot {
}

_processNodeVersions() {
var processLimit = this._nodeUpdateQueue.splice(0, 2500);
if(this._processingNodes) {
log.warn("VoyagerBot", "Already processing nodes from queue - skipping interval check");
return;
}

this._processingNodes = true;
var processLimit = this._nodeUpdateQueue.splice(0, 500);
log.info("VoyagerBot", "Processing " + processLimit.length + " pending node updates. " + this._nodeUpdateQueue.length + " remaining");
for (var obj of processLimit) {
switch (obj.type) {
Expand All @@ -420,6 +428,7 @@ class VoyagerBot {
}
}
log.info("VoyagerBot", "Processed " + processLimit.length + " node updates. " + this._nodeUpdateQueue.length + " remaining");
this._processingNodes = false;
}

_tryUpdateNodeVersions() {
Expand Down Expand Up @@ -496,10 +505,7 @@ class VoyagerBot {
var newVersion = {};
var updated = false;

var defaults = {displayName: '', avatarUrl: '', isAnonymous: true};
if (node.type == 'room') {
defaults.primaryAlias = '';
}
var defaults = {displayName: '', avatarUrl: '', isAnonymous: true, primaryAlias: ''};

// Ensure that `null != ''` doesn't end up triggering an update
this._replaceNulls(meta, defaults);
Expand All @@ -517,7 +523,7 @@ class VoyagerBot {
newVersion.isAnonymous = currentVersion.isAnonymous;
updated = true;
}
if (currentVersion.primaryAlias != meta.primaryAlias) {
if (currentVersion.primaryAlias != meta.primaryAlias && node.type == 'room') {
newVersion.primaryAlias = currentVersion.primaryAlias || '';
updated = true;
}
Expand Down

0 comments on commit e2695a9

Please sign in to comment.