-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(source-iotsitewise): deduplicate batch requests (#629)
- Loading branch information
Showing
8 changed files
with
224 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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
24 changes: 24 additions & 0 deletions
24
packages/source-iotsitewise/src/time-series-data/util/deduplication.spec.ts
This file contains 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,24 @@ | ||
import { deduplicateBatch } from './deduplication'; | ||
|
||
describe('deduplicateBatch', () => { | ||
it('removes duplicate entries from a given batch', () => { | ||
const entry = { | ||
onError: jest.fn(), | ||
onSuccess: jest.fn(), | ||
requestEnd: new Date(2001, 0, 0), | ||
requestStart: new Date(2000, 0, 0), | ||
requestInformation: { | ||
id: 'asset-property', | ||
start: new Date(2001, 0, 0), | ||
end: new Date(2000, 0, 0), | ||
resolution: '0', | ||
fetchMostRecentBeforeEnd: true, | ||
}, | ||
}; | ||
|
||
const originalBatch = [entry, entry]; | ||
const deduplicatedBatch = [entry]; | ||
|
||
expect(deduplicateBatch(originalBatch)).toEqual(deduplicatedBatch); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/source-iotsitewise/src/time-series-data/util/deduplication.ts
This file contains 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,34 @@ | ||
import isEqual from 'lodash.isequal'; | ||
import uniqWith from 'lodash.uniqwith'; | ||
import { BatchAggregatedEntry } from '../client/batchGetAggregatedPropertyDataPoints'; | ||
import { BatchHistoricalEntry } from '../client/batchGetHistoricalPropertyDataPoints'; | ||
import { BatchLatestEntry } from '../client/batchGetLatestPropertyDataPoints'; | ||
|
||
export type Entry = BatchAggregatedEntry | BatchHistoricalEntry | BatchLatestEntry; | ||
|
||
/** | ||
* Given a batch, or array of entries, deduplicate the batch. | ||
*/ | ||
export function deduplicateBatch<T extends Entry>(batch: T[]): T[] { | ||
return uniqWith(batch, compareEntryUniqueness); | ||
} | ||
|
||
/** | ||
* Compares one entry to another, determining if the first is unique. | ||
*/ | ||
function compareEntryUniqueness(a: Entry, b: Entry) { | ||
return isEqual(getEntryRequestInformation(a), getEntryRequestInformation(b)); | ||
} | ||
|
||
/** | ||
* Gets relevant request information off the entry. | ||
*/ | ||
function getEntryRequestInformation(entry: Entry) { | ||
const { | ||
refId: _refId, | ||
cacheSettings: _cacheSettings, | ||
...requestInformationWithoutOmittedFields | ||
} = entry.requestInformation; | ||
|
||
return requestInformationWithoutOmittedFields; | ||
} |