Skip to content

Commit de23f29

Browse files
authored
Fix/domain search incomplete (#384)
* filter out deprecated domains and other non registered domains. * adding retry logic and a way to query the whole domain list. * replace with constant * fixed constant naming * add test for domain list filtering
1 parent 8c9d4f8 commit de23f29

File tree

9 files changed

+162
-9
lines changed

9 files changed

+162
-9
lines changed

server/router/helpers/combine.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const combine = data => (...callbacks) =>
23+
callbacks.reduce(
24+
(accumulator, callback) => (accumulator = callback(accumulator)),
25+
data
26+
);
27+
28+
module.exports = combine;

server/router/helpers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// THE SOFTWARE.
2121

2222
const buildQueryString = require('./build-query-string');
23+
const combine = require('./combine');
2324
const delay = require('./delay');
2425
const isAdvancedVisibilityEnabled = require('./is-advanced-visibility-enabled');
2526
const listWorkflows = require('./list-workflows');
@@ -29,6 +30,7 @@ const replacer = require('./replacer');
2930

3031
module.exports = {
3132
buildQueryString,
33+
combine,
3234
delay,
3335
isAdvancedVisibilityEnabled,
3436
listWorkflows,

server/router/services/domain-service/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121

2222
const DOMAIN_LIST_DELAY_MS = 100;
2323
const DOMAIN_LIST_PAGE_SIZE = 100;
24+
const DOMAIN_LIST_RETRY_MAX = 3;
2425
const DOMAIN_LIST_SEARCH_SIZE = 10;
26+
const DOMAIN_STATUS_REGISTERED = 'REGISTERED';
2527

2628
module.exports = {
2729
DOMAIN_LIST_DELAY_MS,
2830
DOMAIN_LIST_PAGE_SIZE,
31+
DOMAIN_LIST_RETRY_MAX,
2932
DOMAIN_LIST_SEARCH_SIZE,
33+
DOMAIN_STATUS_REGISTERED,
3034
};

server/router/services/domain-service/helpers/fetch-domain-list-next-page.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,46 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
const { DOMAIN_LIST_DELAY_MS, DOMAIN_LIST_PAGE_SIZE } = require('../constants');
22+
const {
23+
DOMAIN_LIST_DELAY_MS,
24+
DOMAIN_LIST_PAGE_SIZE,
25+
DOMAIN_LIST_RETRY_MAX,
26+
} = require('../constants');
2327
const { delay } = require('../../../helpers');
2428

2529
const fetchDomainListNextPage = async ({
2630
ctx,
2731
domainList = [],
2832
nextPageToken = '',
33+
retryCount = 0,
2934
}) => {
30-
const data = await ctx.cadence.listDomains({
31-
pageSize: DOMAIN_LIST_PAGE_SIZE,
32-
nextPageToken: nextPageToken
33-
? Buffer.from(encodeURIComponent(nextPageToken), 'base64')
34-
: undefined,
35-
});
35+
let data;
36+
37+
if (retryCount >= DOMAIN_LIST_RETRY_MAX) {
38+
return domainList;
39+
}
40+
41+
try {
42+
data = await ctx.cadence.listDomains({
43+
pageSize: DOMAIN_LIST_PAGE_SIZE,
44+
nextPageToken: nextPageToken
45+
? Buffer.from(encodeURIComponent(nextPageToken), 'base64')
46+
: undefined,
47+
});
48+
} catch (error) {
49+
console.error(
50+
`fetchDomainListNextPage retry: ${retryCount} error: ${error.toString()}`
51+
);
52+
53+
await delay(DOMAIN_LIST_DELAY_MS);
54+
55+
return fetchDomainListNextPage({
56+
ctx,
57+
nextPageToken,
58+
domainList,
59+
retryCount: retryCount + 1,
60+
});
61+
}
3662

3763
domainList.splice(domainList.length, 0, ...data.domains);
3864

server/router/services/domain-service/helpers/fetch-domain-list.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
const { combine } = require('../../../helpers');
2223
const fetchDomainListNextPage = require('./fetch-domain-list-next-page');
24+
const filterDomainList = require('./filter-domain-list');
2325
const sortDomainList = require('./sort-domain-list');
2426

2527
const fetchDomainList = ctx => async () => {
2628
const domainList = await fetchDomainListNextPage({ ctx });
2729

28-
return sortDomainList(domainList);
30+
return combine(domainList)(filterDomainList, sortDomainList);
2931
};
3032

3133
module.exports = fetchDomainList;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const { DOMAIN_STATUS_REGISTERED } = require('../constants');
23+
24+
const filterDomainList = domainList =>
25+
domainList.filter(
26+
domain => domain.domainInfo.status === DOMAIN_STATUS_REGISTERED
27+
);
28+
29+
module.exports = filterDomainList;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import filterDomainList from './filter-domain-list';
23+
24+
describe('filterDomainList', () => {
25+
describe('when a registered domain is in domainList', () => {
26+
const domainList = [
27+
{
28+
domainInfo: {
29+
status: 'REGISTERED',
30+
},
31+
},
32+
];
33+
34+
it('should return this domain in the returned list.', () => {
35+
const output = filterDomainList(domainList);
36+
37+
expect(output.length).toEqual(1);
38+
});
39+
});
40+
41+
describe('when a deprecated domain is in the domainList', () => {
42+
const domainList = [
43+
{
44+
domainInfo: {
45+
status: 'DEPRECATED',
46+
},
47+
},
48+
];
49+
50+
it('should not return this domain in the returned list.', () => {
51+
const output = filterDomainList(domainList);
52+
53+
expect(output.length).toEqual(0);
54+
});
55+
});
56+
});

server/router/services/domain-service/helpers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121

2222
const fetchDomainListNextPage = require('./fetch-domain-list-next-page');
2323
const fetchDomainList = require('./fetch-domain-list');
24+
const filterDomainList = require('./filter-domain-list');
2425
const getDomainList = require('./get-domain-list');
2526
const getMatchingDomains = require('./get-matching-domains');
2627
const sortDomainList = require('./sort-domain-list');
2728

2829
module.exports = {
2930
fetchDomainListNextPage,
3031
fetchDomainList,
32+
filterDomainList,
3133
getDomainList,
3234
getMatchingDomains,
3335
sortDomainList,

server/router/services/domain-service/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ class DomainService {
2828

2929
async searchDomains(ctx) {
3030
const { cacheManager } = this;
31-
const { querystring } = ctx.query;
31+
const { all, querystring } = ctx.query;
3232

3333
const domainList = await getDomainList({ cacheManager, ctx });
3434

35+
if (all) {
36+
return domainList;
37+
}
38+
3539
return getMatchingDomains({ domainList, querystring });
3640
}
3741
}

0 commit comments

Comments
 (0)