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

Dynamic cache length overriding #2755

Merged
merged 9 commits into from
Jan 15, 2019
Merged

Dynamic cache length overriding #2755

merged 9 commits into from
Jan 15, 2019

Conversation

paulmelnikow
Copy link
Member

For the Endpoint badge: #2473.

request-handler.js is such a bear. I’m looking forward to being able to rewrite it when the service refactor is done.

For the Endpoint badge: #2473.

`request-handler.js` is such a bear. I’m looking forward to being able to rewrite it when the service refactor is done.
@paulmelnikow paulmelnikow added the core Server, BaseService, GitHub auth label Jan 13, 2019
@paulmelnikow paulmelnikow mentioned this pull request Jan 13, 2019
10 tasks
@shields-ci
Copy link

shields-ci commented Jan 13, 2019

Messages
📖 ✨ Thanks for your contribution to Shields, @paulmelnikow!

Generated by 🚫 dangerJS against a0b4a5e

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 13, 2019 17:57 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 13, 2019 17:57 Inactive
@@ -140,9 +147,13 @@ function handleRequest(cacheHeaderConfig, handlerOptions) {
return
}
if (requestCache.has(cacheIndex)) {
const cached = requestCache.get(cacheIndex).data
Copy link
Member Author

Choose a reason for hiding this comment

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

Updated for consistency with same-named variable above.

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 13, 2019 17:59 Inactive
@paulmelnikow paulmelnikow added the blocker PRs and epics which block other work label Jan 13, 2019
@chris48s
Copy link
Member

OK, so having spent some time reading over this, I think I can see what's going on:

You've got defaultCacheLengthSeconds which can be overridden by serviceDefaultCacheLengthSeconds (either by category or on a badge-by-badge basis). Then in turn that can be overridden by serviceOverrideCacheLengthSeconds (which we expect to be used only in the dynamic badge) but only if serviceOverrideCacheLengthSeconds is longer than serviceDefaultCacheLengthSeconds and then the maxAge query param can also override both of those but again only if maxAge is longer.

..yeah? And it also looks correct.

I can see how we've ended up at this point (one edge-case at a time) and I get that its difficult to have a single place in the codebase that encodes all of that logic because we want to introduce each of those params at different layers of the application for different reasons (also I accept that I've contributed some of this complexity). This set of rules is going to be non-obvious to a contributor who isn't already deeply familiar with the codebase and "how long will this badge be cached for" may be a hard question to answer or reason about.

I think as time goes on and we get rid of the rest of the legacy services, we can ditch 2 of these layers, but until that time this set of rules seems like it could really use some docs to explain that chain of overrides. Does that sound reasonable?

@paulmelnikow
Copy link
Member Author

Yes, that is a great summary of what is happening.

Maybe we can just paste it into request-handler.js for now.

The more I understand the code in request-handler.js, the clearer it is that HTTP requests don't need to be intertwined with caching and timeouts. I'm wondering, if the legacy service rewrite is going to take a while longer, if we should go ahead build its replacement. Then we could shim it in reverse: re-implement LegacyService.register to invoke registerLegacyRouteHandler with a made-up sendBadge function that is compatible enough with those services.

@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 14, 2019 22:00 Inactive
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 15, 2019 11:26 Inactive
lib/request-handler.js Outdated Show resolved Hide resolved
chris48s
chris48s previously approved these changes Jan 15, 2019
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

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

seems fair enough

Co-Authored-By: paulmelnikow <github@paulmelnikow.com>
@paulmelnikow paulmelnikow temporarily deployed to shields-staging-pr-2755 January 15, 2019 19:38 Inactive
@paulmelnikow
Copy link
Member Author

Thanks for reviewing!

@shields-deployment
Copy link

This pull request was merged to master branch. This change is now waiting for deployment, which will usually happen within a few days. Stay tuned by joining our #ops channel on Discord!

After deployment, changes are copied to gh-pages branch:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker PRs and epics which block other work core Server, BaseService, GitHub auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants