Skip to content

Commit

Permalink
fix: update hash logic to account for changes in deps (#804)
Browse files Browse the repository at this point in the history
* update files

* remove console

* update test

* improve test and api

---------

Co-authored-by: vigneshshanmugam <[email protected]>
  • Loading branch information
shahzad31 and vigneshshanmugam authored Jul 26, 2023
1 parent e827927 commit 2262f13
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
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 @@ -103,7 +103,7 @@ describe('Monitors', () => {
match: 'test',
},
});
monitor.setContent('foo');
monitor.update({ locations: ['brazil'] });
const schema1 = await buildMonitorSchema([monitor], true);
expect(schema1[0].hash).not.toEqual(schema[0].hash);
});
Expand Down
1 change: 0 additions & 1 deletion src/dsl/journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class Journey {
...config,
});
this.monitor.setSource(this.location);
this.monitor.setContent(this.callback.toString());
this.monitor.setFilter({ match: this.name });
}

Expand Down
1 change: 1 addition & 0 deletions src/dsl/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class Monitor {

/**
* The underlying journey code of the monitor
* along with its dependencies
*/
setContent(content = '') {
this.content = content;
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
20 changes: 13 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(schemas: MonitorSchema[]) {
const data: MonitorHashID[] = [];
for (const monitor of monitors) {
for (const schema of schemas) {
data.push({
journey_id: monitor.config.id,
hash: monitor.hash(),
journey_id: schema.id,
hash: schema.hash,
});
}
return data;
Expand All @@ -137,14 +137,20 @@ 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.setContent(content);
Object.assign(schema, { content, filter });
}
/**
* Generate hash only after the bundled content is created
* to capture code changes in imported files
*/
if (isV2) {
schema.hash = monitor.hash();
}
schemas.push(schema);
}

Expand Down

0 comments on commit 2262f13

Please sign in to comment.