Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: prevent fetching toggles when they are up to date #202
feat: prevent fetching toggles when they are up to date #202
Changes from 24 commits
7d231b0
2fdf1e0
4f42346
ce45d89
bab5000
a181bd5
c9a1677
3683bed
195c438
ebcea49
2f46c6b
ca8ebb9
9463475
9f6a10c
cee9f51
95f126c
5ace0d9
c2f34e2
cf12da6
63d22bf
8c921af
c225d21
54d5ab5
ad853c2
44aa7f1
2d264a6
1556900
bff8282
b595afc
0fc23d1
5bb8c20
5266140
7712d92
4e7a656
7684319
9ecd585
8aec66c
3c20789
c0078f8
9e07183
04cd36e
2fae8e0
0a5d88c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a bit confusing to see updates to existing tests that seems unrelated to the PR. Can you please elaborate on why you needed to modify this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the change looks reasonable tbh, but still would love to see your comments on them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an early version of our implementation, we needed to update this test and actually we realized that the test was not working as it should so we fixed it, but we can remove that if you think that should not be part of this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for a clarification. I would prefer to have it as a separate PR if you do not mind. We can keep it here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding it directly to the config definition, If we could have an optional "experimental" container we could make it clear that this option might go away or be changed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok we are working on it and adding the hashed context. Do you have any proposal for how you would like this to be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello
Concerning the hashed context, we started with the use of this type of library : “object-hash”.
Is this OK for you ?
“unleash-proxy-client” lib size => 5.5 KB
“object-hash” lib size => 10 KB
Which is a significant increase in percentage terms.
Last lib update: 02/2022 (v3.0.0),
Otherwise we can simply use a JSON.stringify (more verbose but which does not depend on anything)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not want to take on a library of this size for this.
I think the JSON.stringify is a good start, and as this is an experimental feature we can use that to learn the performance impact here. In the future we can consider to take advantage of the built in hasing capabilities, supported by most modern browsers (https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the naming could be slightly better. Would love more opinions on the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were not very inspired for this name 😃, I think a combination of the two proposals could be the best?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method have been carefully designed to not use "early returns". Early return in combination with try/catch control flow increases the complexity. I am not comfortable about breaking the current pattern to support avoiding the initial fetch use case.
I think we instead can have a specific
initialFetchMethod
, that only callsfetchToggles
if the cached data is not considered recent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By running this on each fetch we have another potential bug in the future: What if the stored timestamp somehow ends up far in to the future (we are dealing with untrusted browsers) we will never try to fetch updates at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you're right, the
initialFetchMethod
is a better idea than this, we will rework it.Come to think of it, this code is actually buggy... because if we update the context and the
isUpToDate
function says "yes", the flags will not be updated, which is not intended.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "untrusted browsers", what could be the behavior on them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything in user-land cannot be trusted. Users might suddenly change their local time etc, which forces us to be a bit restrictive on what we trust. E.g. if the stored data is 2 hours in the future we should probably disregard the cached data and do a fetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should happen when we get a positive response from the server (2xx or 304).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes this is the case no?