fix: scope live revisions to worker generations (#383)
This commit is contained in:
1 parent
5c2c0383df
commit
2253c40577
7 files changed
+111
-19
No files matched your search
@@ -1,3 +1,15 @@
|
||||
function buildLiveRevisionQuery(revisions = {}) {
|
||||
const params = new URLSearchParams();
|
||||
const tokenPattern = /^[0-9a-f]{16}\.[0-9]{1,20}$/;
|
||||
['context', 'events', 'notifications'].forEach((section) => {
|
||||
const revision = revisions[section];
|
||||
if (typeof revision === 'string' && tokenPattern.test(revision)) {
|
||||
params.set(section + '_revision', revision);
|
||||
}
|
||||
});
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
function createContextPoller({
|
||||
fetchContext,
|
||||
onSnapshot,
|
||||
@@ -123,6 +135,8 @@ function createContextPoller({
|
||||
};
|
||||
}
|
||||
|
||||
createContextPoller.buildRevisionQuery = buildLiveRevisionQuery;
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = createContextPoller;
|
||||
}
|
||||
@@ -324,11 +324,7 @@
|
||||
setClock(); setInterval(setClock, 1000);
|
||||
|
||||
async function fetchLiveSnapshot(revisions = {}, { signal } = {}) {
|
||||
const params = new URLSearchParams();
|
||||
Object.entries(revisions).forEach(([section, revision]) => {
|
||||
if (Number.isInteger(revision) && revision >= 0) params.set(section + '_revision', revision);
|
||||
});
|
||||
const query = params.toString();
|
||||
const query = createContextPoller.buildRevisionQuery(revisions);
|
||||
const res = await fetch('api/v1/live' + (query ? '?' + query : ''), {
|
||||
headers: { Accept: 'application/json' },
|
||||
signal,
|
||||
|
||||
Reference in new issue
Block a user