This repository was archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
[WIP] refactor(hapi): Upgrade to hapi 17 #334
Open
deeptibaghel
wants to merge
14
commits into
mozilla:master
Choose a base branch
from
deeptibaghel:hapi17
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c54bf24
refactor(hapi): Upgrade to hapi 17
deeptibaghel 6c6efb7
refactor(hapi): Upgrade to hapi 17
deeptibaghel 45961cc
refactor(hapi): Upgrade to hapi 17
deeptibaghel 5d6d962
refactor(hapi): Upgrade to hapi 17
deeptibaghel e093671
refactor(hapi): Upgrade to hapi 17
deeptibaghel 67baebb
refactor(hapi): Upgrade to hapi 17
deeptibaghel 5a2120d
refactor(hapi): Upgrade to hapi 17
deeptibaghel bd92760
refactor(hapi): Upgrade to hapi 17
deeptibaghel c6826cb
refactor(hapi): Upgrade to hapi 17
deeptibaghel 67f7850
refactor(hapi): Upgrade to hapi 17
deeptibaghel 42027ec
refactor(hapi): Upgrade to hapi 17
deeptibaghel d2e11c4
refactor(hapi): Upgrade to hapi 17
deeptibaghel a34c6a7
refactor(hapi): Upgrade to hapi 17
deeptibaghel 25bf02c
refactor(hapi): Upgrade to hapi 17
deeptibaghel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ extends: plugin:fxa/server | |
| rules: | ||
| handle-callback-err: 0 | ||
| semi: [2, "always"] | ||
|
|
||
| parserOptions: | ||
| ecmaVersion: 2018 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,28 +51,27 @@ function getProfileCacheKey(req) { | |
| } | ||
|
|
||
|
|
||
| module.exports = function profileCache(server, options, next) { | ||
| module.exports = function profileCache(server, options) { | ||
|
|
||
| // Fetch all available profile data given the scopes on the request, | ||
| // using cached data if possible. | ||
|
|
||
| server.method('profileCache.get', (req, next) => { | ||
| batch(req, { | ||
| server.method('profileCache.get', (req) => { | ||
| return batch(req, { | ||
| '/v1/_core_profile': true, | ||
| '/v1/uid': true, | ||
| '/v1/avatar': ['avatar', 'avatarDefault'], | ||
| '/v1/display_name': true | ||
| }) | ||
| .then(result => { | ||
| // Only cache the result if we can produce a suitable cache key. | ||
| const ttl = getProfileCacheKey(req) ? undefined : 0; | ||
| return next(null, result, ttl); | ||
| }) | ||
| .catch(next); | ||
| .then((result) => { | ||
| // Only cache the result if we can produce a suitable cache key. | ||
| const ttl = getProfileCacheKey(req) ? undefined : 0; | ||
| return { result, ttl }; | ||
| }); | ||
| }, { | ||
| cache: { | ||
| expiresIn: options.expiresIn, | ||
| generateTimeout: options.generateTimeout | ||
| generateTimeout: options.generateTimeout || 100 | ||
| }, | ||
| generateKey: (req) => { | ||
| return getProfileCacheKey(req) || 'can-not-cache'; | ||
|
|
@@ -81,24 +80,20 @@ module.exports = function profileCache(server, options, next) { | |
|
|
||
| // Drop any cached profile data for the given user. | ||
|
|
||
| server.method('profileCache.drop', (uid, next) => { | ||
| server.method('profileCache.drop', (uid) => { | ||
| // To work transparently with hapi's caching and `getProfileCacheKey` above, | ||
| // we make a bunch of synthetic request objects on which to drop the | ||
| // cache, one for each possible set of scopes in the cache. | ||
| return P.each(CACHEABLE_SCOPES, scope => { | ||
| return P.each(CACHEABLE_SCOPES, (scope) => { | ||
| const req = { auth: { credentials: { | ||
| user: uid, | ||
| scope: scope | ||
| }}}; | ||
| return P.fromCallback(cb => { | ||
| server.methods.profileCache.get.cache.drop(req, cb); | ||
| return server.methods.profileCache.get.cache.drop(req); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vladikoff the test to upload avatar fails at this point |
||
| }) | ||
| .catch((err) => { | ||
| throw err; | ||
| }); | ||
| }).asCallback(next); | ||
| }); | ||
|
|
||
| next(); | ||
| }; | ||
|
|
||
| module.exports.attributes = { | ||
| name: 'fxa-profile-cache' | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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 we change that in the tests instead and should not do this here
Uh oh!
There was an error while loading. Please reload this page.
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.
it was throwing error here
generateTimeout is requiredso i added it temporarily