This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 376
fix: Move persistence layer's delta computation into worker #5563
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
18037c3
fix: Move persistence layer's delta computation into worker
lei9444 43a25b5
Merge branch 'main' into worker
lei9444 b11ad9e
fix unit testsa
lei9444 45bb262
Merge branch 'worker' of https://github.com/lei9444/BotFramework-Comp…
lei9444 c06b468
fix tests
lei9444 9624333
fix tests
lei9444 5b41f53
add test coverage
lei9444 e5d65f1
Merge branch 'main' into worker
boydc2014 b442273
Merge branch 'main' into worker
lei9444 233ccf4
Merge branch 'main' into worker
lei9444 00351b5
update naming
lei9444 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Composer/packages/client/src/recoilModel/parsers/calculator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { FileAsset } from '../persistence/types'; | ||
|
|
||
| import Worker from './workers/calculator.worker.ts'; | ||
| import { BaseWorker } from './baseWorker'; | ||
| import { FilesDifferencePayload, CalculatorType } from './types'; | ||
|
|
||
| // Wrapper class | ||
| class Calculator extends BaseWorker<CalculatorType> { | ||
| difference(target: FileAsset[], origin: FileAsset[]) { | ||
| const payload = { target, origin }; | ||
| return this.sendMsg<FilesDifferencePayload>('difference', payload); | ||
| } | ||
| } | ||
|
|
||
| export default new Calculator(new Worker()); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Composer/packages/client/src/recoilModel/parsers/workers/calculator.worker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| import isEqual from 'lodash/isEqual'; | ||
| import differenceWith from 'lodash/differenceWith'; | ||
|
|
||
| import { FileAsset } from '../../persistence/types'; | ||
|
|
||
| import { CalculatorType, FilesDifferencePayload } from './../types'; | ||
|
|
||
| type DifferenceMessage = { | ||
| id: string; | ||
| type: CalculatorType; | ||
| payload: FilesDifferencePayload; | ||
| }; | ||
|
|
||
| type MessageEvent = DifferenceMessage; | ||
|
|
||
| const ctx: Worker = self as any; | ||
|
|
||
| export function getDifferenceItems(target: FileAsset[], origin: FileAsset[]) { | ||
| const changes1 = differenceWith(target, origin, isEqual); | ||
| const changes2 = differenceWith(origin, target, isEqual); | ||
| const deleted = changes2.filter((change) => !target.some((file) => change.id === file.id)); | ||
| const { updated, added } = changes1.reduce( | ||
| (result: { updated: FileAsset[]; added: FileAsset[] }, change) => { | ||
| if (origin.some((file) => change.id === file.id)) { | ||
| result.updated.push(change); | ||
| } else { | ||
| result.added.push(change); | ||
| } | ||
|
|
||
| return result; | ||
| }, | ||
| { updated: [], added: [] } | ||
| ); | ||
|
|
||
| return { updated, added, deleted }; | ||
| } | ||
|
|
||
| function handleMessage(message: MessageEvent) { | ||
| const { type, payload } = message; | ||
|
|
||
| switch (type) { | ||
| case 'difference': { | ||
| const { target, origin } = payload; | ||
| return getDifferenceItems(target, origin); | ||
| } | ||
| default: { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| ctx.onmessage = function (event) { | ||
| const msg = event.data as MessageEvent; | ||
| try { | ||
| const result = handleMessage(msg); | ||
| ctx.postMessage({ id: msg.id, payload: result }); | ||
| } catch (error) { | ||
| ctx.postMessage({ id: msg.id, error: error.message }); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.