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

Clean up some helpers #1117

Merged
merged 8 commits into from
Oct 6, 2017
Merged

Clean up some helpers #1117

merged 8 commits into from
Oct 6, 2017

Conversation

paulmelnikow
Copy link
Member

Address comments from #1109.

Address comments from #1109.
@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth, Shared helpers label Oct 2, 2017
Copy link
Member

@Daniel15 Daniel15 left a comment

Choose a reason for hiding this comment

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

This looks good to me. However, the change from Object.create(null) to new Map is not doing what you expect - You need to use the Map's get and set methods. Doing map[foo] is setting a property on the map object, rather than actually setting a value in the map. lol javascript

@@ -120,7 +120,7 @@ function sendTokenToAllServers(token) {
strictSSL: false,
};
request(options, function(err, res, body) {
if (err != null) { return reject('Posting the GitHub user token failed: ' + err.stack); }
if (err != null) { return reject(err); }
Copy link
Member

Choose a reason for hiding this comment

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

Could do return reject(new Error('Posting the GitHub user token failed: ' + err.message)) or something similar. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea… I thought about that. This is called in a loop, and the calling code already has something really similar to that. It feels redundant to prefix it twice.

return false;
}
const pattern = /(\d+\.)*\d-SNAPSHOT/;
return version && version.match(pattern);
Copy link
Member

Choose a reason for hiding this comment

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

Nice.

@@ -4,7 +4,7 @@ const request = require('request');

// Map from URL to { timestamp: last fetch time, interval: in milliseconds,
// data: data }.
let regularUpdateCache = Object.create(null);
let regularUpdateCache = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

All regularUpdateCache[url] need to be changed to either regularUpdateCache.get(url) or regularUpdateCache.set(url, value) in order to use Map

Copy link
Member Author

Choose a reason for hiding this comment

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

We have no unit test or service test coverage on regularUpdate. I started to write unit tests but think the time is better spent integrating a library like https://github.com/ptarjan/node-cache or https://github.com/mpneuried/nodecache, which have their own tests, than maintaining this code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to reset these changes.

@paulmelnikow
Copy link
Member Author

Haha, thanks for the education on Map! 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Server, BaseService, GitHub auth, Shared helpers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants