Skip to content

Commit

Permalink
Merge pull request #1274 from Ubitso/master
Browse files Browse the repository at this point in the history
Remove unnecessary clone in node update method
  • Loading branch information
icebob authored Mar 31, 2024
2 parents e39e675 + db23a16 commit 0d88cca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/registry/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

"use strict";

const _ = require("lodash");

/**
* Node class
*
Expand Down Expand Up @@ -62,8 +60,7 @@ class Node {
this.client = payload.client || {};
this.config = payload.config || {};

// Process services & events (should make a clone because it will manipulate the objects (add handlers))
this.services = _.cloneDeep(payload.services);
this.services = payload.services;
this.rawInfo = payload;

const newSeq = payload.seq || 1;
Expand Down
25 changes: 15 additions & 10 deletions src/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,28 +300,31 @@ class Registry {
_.forIn(actions, action => {
if (!this.checkActionVisibility(action, node)) return;

// Clone fields to have independent action object
const serviceAction = { ...action };

if (node.local) {
action.handler = this.broker.middlewares.wrapHandler(
serviceAction.handler = this.broker.middlewares.wrapHandler(
"localAction",
action.handler,
action
);
} else if (this.broker.transit) {
action.handler = this.broker.middlewares.wrapHandler(
serviceAction.handler = this.broker.middlewares.wrapHandler(
"remoteAction",
this.broker.transit.request.bind(this.broker.transit),
{ ...action, service }
);
}
if (this.broker.options.disableBalancer && this.broker.transit)
action.remoteHandler = this.broker.middlewares.wrapHandler(
serviceAction.remoteHandler = this.broker.middlewares.wrapHandler(
"remoteAction",
this.broker.transit.request.bind(this.broker.transit),
{ ...action, service }
);

this.actions.add(node, service, action);
service.addAction(action);
this.actions.add(node, service, serviceAction);
service.addAction(serviceAction);
});
}

Expand Down Expand Up @@ -426,15 +429,17 @@ class Registry {
*/
registerEvents(node, service, events) {
_.forIn(events, event => {
const serviceEvent = { ...event };

if (node.local)
event.handler = this.broker.middlewares.wrapHandler(
serviceEvent.handler = this.broker.middlewares.wrapHandler(
"localEvent",
event.handler,
event
serviceEvent.handler,
serviceEvent
);

this.events.add(node, service, event);
service.addEvent(event);
this.events.add(node, service, serviceEvent);
service.addEvent(serviceEvent);
});
}

Expand Down

0 comments on commit 0d88cca

Please sign in to comment.