Skip to content
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

fix: update hash logic to account for bundling #804

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ __tests__/e2e/junit.xml
seccomp/build

test-projects/

.DS_Store
2 changes: 1 addition & 1 deletion __tests__/push/monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Monitors', () => {
});
monitor.setContent('foo');
const schema1 = await buildMonitorSchema([monitor], true);
expect(schema1[0].hash).not.toEqual(schema[0].hash);
expect(schema1[0].hash).toEqual(schema[0].hash);
});

it('parse @every schedule format', async () => {
Expand Down
9 changes: 5 additions & 4 deletions src/push/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ export async function push(monitors: Monitor[], options: PushOptions) {
return await pushLegacy(monitors, options);
}

const local = getLocalMonitors(monitors);
const { monitors: remote } = await bulkGetMonitors(options);

progress(`bundling ${monitors.length} monitors`);
const schemas = await buildMonitorSchema(monitors, true);
const local = getLocalMonitors(schemas);

const { newIDs, changedIDs, removedIDs, unchangedIDs } = diffMonitorHashIDs(
local,
remote
Expand All @@ -83,9 +87,6 @@ export async function push(monitors: Monitor[], options: PushOptions) {

const updatedMonitors = new Set<string>([...changedIDs, ...newIDs]);
if (updatedMonitors.size > 0) {
const toBundle = monitors.filter(m => updatedMonitors.has(m.config.id));
progress(`bundling ${toBundle.length} monitors`);
const schemas = await buildMonitorSchema(toBundle, true);
const chunks = getChunks(schemas, CHUNK_SIZE);
for (const chunk of chunks) {
await liveProgress(
Expand Down
16 changes: 9 additions & 7 deletions src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export function diffMonitors(
return result;
}

export function getLocalMonitors(monitors: Monitor[]) {
export function getLocalMonitors(monitorSchemas: MonitorSchema[]) {
const data: MonitorHashID[] = [];
for (const monitor of monitors) {
for (const monitor of monitorSchemas) {
data.push({
journey_id: monitor.config.id,
hash: monitor.hash(),
journey_id: monitor.id,
hash: monitor.hash,
});
}
return data;
Expand All @@ -137,14 +137,16 @@ export async function buildMonitorSchema(monitors: Monitor[], isV2: boolean) {
...config,
locations: translateLocation(config.locations),
};
if (isV2) {
schema.hash = monitor.hash();
}

if (type === 'browser') {
const outPath = join(bundlePath, config.name + '.zip');
const content = await bundler.build(source.file, outPath);
monitor.content = content;
Object.assign(schema, { content, filter });
}
if (isV2) {
schema.hash = monitor.hash();
}
schemas.push(schema);
}

Expand Down