Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion meshuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5776,6 +5776,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
parent.parent.DispatchEvent(targets, obj, event);
}
parent.InvalidateNodeCache(newuser, node.meshid, node._id)
}
}

Expand All @@ -5794,7 +5795,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
parent.parent.DispatchEvent(dispatchTargets, obj, event);
}

if (command.responseid != null) { obj.send({ action: 'adddeviceuser', responseid: command.responseid, result: 'ok' }); }
});
}
Expand Down Expand Up @@ -5920,6 +5920,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
failCount++;
}
}
parent.FlushGetNodeRightsCache()

if ((successCount == 0) && (failCount == 0)) { msgs.push("Nothing done"); }

Expand Down
20 changes: 19 additions & 1 deletion webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9174,7 +9174,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
const cacheid = user._id + '/' + meshid + '/' + nodeid;
const cache = GetNodeRightsCache[cacheid];
if (cache != null) { if (cache.t > Date.now()) { return cache.o; } else { GetNodeRightsCacheCount--; } } // Cache hit, or we need to update the cache
if (GetNodeRightsCacheCount > 2000) { GetNodeRightsCache = {}; GetNodeRightsCacheCount = 0; } // From time to time, flush the cache
if (GetNodeRightsCacheCount > 2000) { obj.FlushGetNodeRightsCache() } // From time to time, flush the cache

var r = obj.GetMeshRights(user, mesh);
if (r == 0xFFFFFFFF) {
Expand Down Expand Up @@ -9207,6 +9207,24 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
return out;
}

obj.InvalidateNodeCache = function (user, mesh, nodeid) {
if ((user == null) || (mesh == null) || (nodeid == null)) { return 0; }
if (typeof user == 'string') { user = obj.users[user]; }
if (user == null) { return 0; }
var meshid;
if (typeof mesh == 'string') { meshid = mesh; } else if ((typeof mesh == 'object') && (typeof mesh._id == 'string')) { meshid = mesh._id; } else return 0;

// Check if we have this in the cache
const cacheid = user._id + '/' + meshid + '/' + nodeid;
delete GetNodeRightsCache[cacheid];
GetNodeRightsCacheCount--;
}

obj.FlushGetNodeRightsCache = function() {
GetNodeRightsCache = {};
GetNodeRightsCacheCount = 0;
}

// Returns a list of displatch targets for a given mesh
// We have to target the meshid and all user groups for this mesh, plus any added targets
obj.CreateMeshDispatchTargets = function (mesh, addedTargets) {
Expand Down
Loading