Skip to content

Commit d334099

Browse files
authored
fix: set code and content surrogate keys for json 404 (#692) (#698)
fixes #688
1 parent 23c8388 commit d334099

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/json-pipe.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,24 @@ async function fetchJsonContent(state, req, res) {
8787

8888
updateLastModified(state, res, extractLastModified(ret.headers));
8989
} else {
90-
state.content.sourceBus = 'content';
90+
// also add code surrogate key in case json is later added to code bus (#688)
91+
state.content.sourceBus = 'code|content';
9192
res.status = ret.status === 404 ? 404 : 502;
9293
res.error = `failed to load ${state.info.resourcePath}: ${ret.status}`;
9394
}
9495
}
9596

9697
async function computeSurrogateKeys(state) {
9798
const keys = [];
98-
const pathKey = state.content?.sourceBus === 'code'
99-
? `${state.ref}--${state.repo}--${state.owner}${state.info.path}`
100-
: `${state.contentBusId}${state.info.path}`;
101-
102-
keys.push(await computeSurrogateKey(pathKey));
103-
if (state.content?.sourceBus === 'content') {
104-
keys.push(state.contentBusId);
105-
} else {
99+
if (state.content.sourceBus.includes('code')) {
100+
keys.push(await computeSurrogateKey(`${state.ref}--${state.repo}--${state.owner}${state.info.path}`));
106101
keys.push(`${state.ref}--${state.repo}--${state.owner}_code`);
107102
}
103+
if (state.content.sourceBus.includes('content')) {
104+
keys.push(await computeSurrogateKey(`${state.contentBusId}${state.info.path}`));
105+
keys.push(state.contentBusId);
106+
}
107+
108108
return keys;
109109
}
110110

test/json-pipe.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('JSON Pipe Test', () => {
240240
'access-control-allow-origin': '*',
241241
'content-security-policy': 'default-src \'self\'',
242242
'x-error': 'failed to load /en/index.json: 404',
243-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar',
243+
'x-surrogate-key': 'SIMSxecp2CJXqGYs ref--repo--owner_code Atrz_qDg26DmSe9a foobar',
244244
});
245245
});
246246

0 commit comments

Comments
 (0)