-
Notifications
You must be signed in to change notification settings - Fork 107
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
Feature/domain service #361
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f55512d
Added cache manager which handles caching on server. cache logic is n…
just-at-uber cbc6c6c
Added domain service which allows searching for a domain.
just-at-uber a2eb5db
added test for fetchDomainListNextPage and fixed bug in implementation
just-at-uber 860ff0d
add test for sortDomainList
just-at-uber e3ee6b2
adding tests for getMatchingDomains
just-at-uber 3ff0ae7
Merge branch 'master' into feature/domain-service
just-at-uber 69ebd37
fixup failed conflict resolution
just-at-uber 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 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const delay = time => new Promise(resolve => setTimeout(resolve, time)); | ||
|
||
module.exports = delay; |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const DOMAIN_LIST_DELAY_MS = 100; | ||
const DOMAIN_LIST_PAGE_SIZE = 100; | ||
const DOMAIN_LIST_SEARCH_SIZE = 10; | ||
|
||
module.exports = { | ||
DOMAIN_LIST_DELAY_MS, | ||
DOMAIN_LIST_PAGE_SIZE, | ||
DOMAIN_LIST_SEARCH_SIZE, | ||
}; |
52 changes: 52 additions & 0 deletions
52
server/router/services/domain-service/helpers/fetch-domain-list-next-page.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const { DOMAIN_LIST_DELAY_MS, DOMAIN_LIST_PAGE_SIZE } = require('../constants'); | ||
const { delay } = require('../../../helpers'); | ||
|
||
const fetchDomainListNextPage = async ({ | ||
ctx, | ||
domainList = [], | ||
nextPageToken = '', | ||
}) => { | ||
const data = await ctx.cadence.listDomains({ | ||
pageSize: DOMAIN_LIST_PAGE_SIZE, | ||
nextPageToken: nextPageToken | ||
? Buffer.from(encodeURIComponent(nextPageToken), 'base64') | ||
: undefined, | ||
}); | ||
|
||
domainList.splice(domainList.length, 0, ...data.domains); | ||
|
||
if (!data.nextPageToken) { | ||
return domainList; | ||
} | ||
|
||
await delay(DOMAIN_LIST_DELAY_MS); | ||
|
||
return fetchDomainListNextPage({ | ||
ctx, | ||
nextPageToken: data.nextPageToken, | ||
domainList, | ||
}); | ||
}; | ||
|
||
module.exports = fetchDomainListNextPage; |
81 changes: 81 additions & 0 deletions
81
server/router/services/domain-service/helpers/fetch-domain-list-next-page.spec.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { delay } from '../../../helpers'; | ||
import fetchDomainListNextPage from './fetch-domain-list-next-page'; | ||
|
||
jest.mock('../../../helpers', () => ({ | ||
delay: jest.fn(), | ||
})); | ||
|
||
describe('fetchDomainListNextPage', () => { | ||
const getMockContext = domainResponse => { | ||
const ctx = { | ||
cadence: { | ||
listDomains: jest.fn().mockImplementation(() => domainResponse), | ||
}, | ||
}; | ||
|
||
return ctx; | ||
}; | ||
|
||
describe('when no nextPageToken returned', () => { | ||
it('should return domainList.', async () => { | ||
const domains = ['domain1', 'domain2']; | ||
const domainResponse = { | ||
domains, | ||
}; | ||
|
||
const ctx = getMockContext(domainResponse); | ||
|
||
const domainList = await fetchDomainListNextPage({ | ||
ctx, | ||
}); | ||
|
||
expect(domainList).toEqual(domains); | ||
}); | ||
}); | ||
|
||
describe('when nextPageToken is returned', () => { | ||
it('should call delay and should call itself again to get next domain list page.', async () => { | ||
const nextPageToken = '1234'; | ||
const domains1 = ['domain1', 'domain2']; | ||
const domains2 = ['domain3', 'domain4']; | ||
const domainResponse = { | ||
domains: domains1, | ||
nextPageToken, | ||
}; | ||
|
||
const ctx = getMockContext(domainResponse); | ||
|
||
delay.mockImplementation(() => { | ||
domainResponse.domains = domains2; | ||
domainResponse.nextPageToken = null; | ||
}); | ||
|
||
const domainList = await fetchDomainListNextPage({ | ||
ctx, | ||
}); | ||
|
||
expect(domainList).toEqual([...domains1, ...domains2]); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
server/router/services/domain-service/helpers/fetch-domain-list.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const fetchDomainListNextPage = require('./fetch-domain-list-next-page'); | ||
const sortDomainList = require('./sort-domain-list'); | ||
|
||
const fetchDomainList = ctx => async () => { | ||
const domainList = await fetchDomainListNextPage({ ctx }); | ||
|
||
return sortDomainList(domainList); | ||
}; | ||
|
||
module.exports = fetchDomainList; |
27 changes: 27 additions & 0 deletions
27
server/router/services/domain-service/helpers/get-domain-list.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const fetchDomainList = require('./fetch-domain-list'); | ||
|
||
const getDomainList = ({ cacheManager, ctx }) => | ||
cacheManager.get(fetchDomainList(ctx)); | ||
|
||
module.exports = getDomainList; |
46 changes: 46 additions & 0 deletions
46
server/router/services/domain-service/helpers/get-matching-domains.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const { DOMAIN_LIST_SEARCH_SIZE } = require('../constants'); | ||
|
||
const getMatchingDomains = ({ domainList, querystring }) => { | ||
if (!querystring) { | ||
return domainList.slice(0, DOMAIN_LIST_SEARCH_SIZE); | ||
} | ||
|
||
const matchedDomainList = []; | ||
|
||
for (let i = 0; i < domainList.length; i++) { | ||
if (matchedDomainList.length === DOMAIN_LIST_SEARCH_SIZE) { | ||
return matchedDomainList; | ||
} | ||
|
||
const domain = domainList[i]; | ||
|
||
if (domain.domainInfo.name.indexOf(querystring) !== -1) { | ||
matchedDomainList.push(domain); | ||
} | ||
} | ||
|
||
return matchedDomainList; | ||
}; | ||
|
||
module.exports = getMatchingDomains; |
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.
do you need a case where the cache is updated and the result set changed during pagination?
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 don't think that case can occur in the same request.
so to put another way:
say request1 is using the cached version
following path from
server/router/services/domain-service/index.js
calls
getDomainList
which asks cacheManager if it needs new request or not to cadence server, it will simply return domainList which is cached.Then continues to getMatchingDomains based on the querystring the user typed.
now say request2 occurs after cache period expires
calls
getDomainList
which asks cacheManager if it needs new request or not to cadence server, it will then fetch next page until nextPageToken returns undefined. then returns domain list and calls getMatchingDomainsThere 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.
cadence-server will continue to paginate even if the result has changed since is my understanding