Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stopID caching to prevent excessive findStop calls #8

Merged
merged 8 commits into from
Dec 15, 2022

Conversation

VDenisyuk
Copy link
Contributor

The current implementation (IMHO) generates excessive requests to dvb.findStop() method, as it is not really required to search for a station ID during every update request.
As per my understanding, we need to get stopID when:

  • The module is starting.
  • A user has changed the config and inserted new/other stop.

Therefore, I added intermediate storing mechanism for stopID and stopName.
stopID searching is triggered only in above mentioned two cases, otherwise only dvb.monitor() is triggered.

node_helper.js Outdated
});
}
});
if (!self.stop.id || self.stop.name != payload.stopName) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please verify how the module behaves in case multiple instances are configured? As per my understanding NodeHelper is a single instance per module type, i.e. notifications from different modules with potentially different stop ids will be received. Since the stop variable in the NodeHelper contains a single value it will be flipping and, finally, no calls to dvb.findStop will be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Working on it.

@VDenisyuk
Copy link
Contributor Author

So, now it seems to be solved and tested on two modules simultaneously.
To solve it, I've done:

  1. Registration mechanism. Upon start, every module registers its ID to node_helper using a dedicated call (message label REGISTER-MODULE). The helper registers the module (creates an empty object with module ID) and replies with an acknowledgment (message label REGISTER-ACK). When the module receives the acknowledgment, it starts normal polling.
  2. Separate stop ID and name for every module. The registration mechanism allows us to keep a stop ID and name separately for every registered module.

@skastenholz skastenholz merged commit 29f1fe1 into skastenholz:master Dec 15, 2022
@skastenholz
Copy link
Owner

Thanks for your contribution!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants