-
Notifications
You must be signed in to change notification settings - Fork 3k
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
After revert: Defer local updates if there are missing updates and only call GetMissingOnyxMessages
once
#39683
Merged
danieldoglas
merged 45 commits into
Expensify:main
from
margelo:@chrispader/GetMissingOnyxMessages-deferred-updates-after-revert
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
068e624
Revert "Merge pull request #39668 from Expensify/revert-38997-@chrisp…
chrispader 1a8528c
remove queue clearing and add TS type guard for OnyxUpdate
chrispader e52db00
fix: type check
chrispader 2e13b36
simplify code
chrispader 4fbbd9a
simplify code
chrispader 9eaa455
fix: and simplify
chrispader c134283
add comment
chrispader 36c9ad6
rename variables
chrispader c34337f
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 48fa52e
remove unnecessary pause
chrispader beb16a3
check for isLoadingApp and ActiveClientManager first
chrispader 1d396e1
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 5f1bb97
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 4cdaf5d
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 26ded32
minor improvements of OnyxUpdateMangaer
chrispader e21abf5
implement tests
chrispader cbe2d9f
add exports for testing
chrispader 2a29079
fix: test implementation
chrispader 28004cb
implement proxy for OnyxUpdateManager
chrispader 70e428e
update tests
chrispader 0890696
extract util logic from OnyxUpdateManager
chrispader 909b5a8
extract createProxyForValue and further split up utils
chrispader c502513
fix: tests
chrispader 001eb3a
extract mocks from test
chrispader 4eaf83a
apply updaes
chrispader 9910943
remove unnecessary promise trigger code
chrispader b078cfa
update tests and mocks
chrispader cf3b7e6
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 2c50853
fix: ts
chrispader 3904ef4
fix: tests
chrispader abff1aa
move specific mocks to mock folders
chrispader 39387f6
fix: update mocks and tests
chrispader 6327968
simplify
chrispader b0a70ba
fix: update mocks, tests and test utils to allow for broader E2E tests
chrispader d0e3b68
add more tests and comments
chrispader 52ad15a
remove waitForBatchedChanges
chrispader a7aac11
rename and move helper function
chrispader 95fc4f6
add isPaused checker function to SequentialQueue
chrispader 3e8bc28
reset more things before each test
chrispader 5e42e99
add another test
chrispader f57a149
fix: first test
chrispader 0bb6a51
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader a738a51
remove unused line
chrispader 23eab2d
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader f48d931
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
chrispader 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type {OnyxUpdatesFromServer} from '@src/types/onyx'; | ||
|
||
type DeferredUpdatesDictionary = Record<number, OnyxUpdatesFromServer>; | ||
|
||
type DetectGapAndSplitResult = {applicableUpdates: DeferredUpdatesDictionary; updatesAfterGaps: DeferredUpdatesDictionary; latestMissingUpdateID: number | undefined}; | ||
|
||
export type {DeferredUpdatesDictionary, DetectGapAndSplitResult}; |
34 changes: 34 additions & 0 deletions
34
src/libs/actions/OnyxUpdateManager/utils/__mocks__/applyUpdates.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 Onyx from 'react-native-onyx'; | ||
import type {DeferredUpdatesDictionary} from '@libs/actions/OnyxUpdateManager/types'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import createProxyForObject from '@src/utils/createProxyForObject'; | ||
|
||
let lastUpdateIDAppliedToClient = 0; | ||
Onyx.connect({ | ||
key: ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, | ||
callback: (value) => (lastUpdateIDAppliedToClient = value ?? 0), | ||
}); | ||
|
||
type ApplyUpdatesMockValues = { | ||
onApplyUpdates: ((updates: DeferredUpdatesDictionary) => Promise<void>) | undefined; | ||
}; | ||
|
||
type ApplyUpdatesMock = { | ||
applyUpdates: jest.Mock<Promise<[]>, [updates: DeferredUpdatesDictionary]>; | ||
mockValues: ApplyUpdatesMockValues; | ||
}; | ||
|
||
const mockValues: ApplyUpdatesMockValues = { | ||
onApplyUpdates: undefined, | ||
}; | ||
const mockValuesProxy = createProxyForObject(mockValues); | ||
|
||
const applyUpdates = jest.fn((updates: DeferredUpdatesDictionary) => { | ||
const lastUpdateIdFromUpdates = Math.max(...Object.keys(updates).map(Number)); | ||
return (mockValuesProxy.onApplyUpdates === undefined ? Promise.resolve() : mockValuesProxy.onApplyUpdates(updates)).then(() => | ||
Onyx.set(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, Math.max(lastUpdateIDAppliedToClient, lastUpdateIdFromUpdates)), | ||
); | ||
}); | ||
|
||
export {applyUpdates, mockValuesProxy as mockValues}; | ||
export type {ApplyUpdatesMock}; |
32 changes: 32 additions & 0 deletions
32
src/libs/actions/OnyxUpdateManager/utils/__mocks__/index.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,32 @@ | ||
import type {DeferredUpdatesDictionary, DetectGapAndSplitResult} from '@libs/actions/OnyxUpdateManager/types'; | ||
import createProxyForObject from '@src/utils/createProxyForObject'; | ||
import type * as OnyxUpdateManagerUtilsImport from '..'; | ||
import {applyUpdates} from './applyUpdates'; | ||
|
||
const UtilsImplementation: typeof OnyxUpdateManagerUtilsImport = jest.requireActual('@libs/actions/OnyxUpdateManager/utils'); | ||
|
||
type OnyxUpdateManagerUtilsMockValues = { | ||
onValidateAndApplyDeferredUpdates: ((clientLastUpdateID?: number) => Promise<void>) | undefined; | ||
}; | ||
|
||
type OnyxUpdateManagerUtilsMock = typeof UtilsImplementation & { | ||
detectGapsAndSplit: jest.Mock<Promise<DetectGapAndSplitResult>, [updates: DeferredUpdatesDictionary, clientLastUpdateID?: number]>; | ||
validateAndApplyDeferredUpdates: jest.Mock<Promise<void>, [clientLastUpdateID?: number]>; | ||
mockValues: OnyxUpdateManagerUtilsMockValues; | ||
}; | ||
|
||
const mockValues: OnyxUpdateManagerUtilsMockValues = { | ||
onValidateAndApplyDeferredUpdates: undefined, | ||
}; | ||
const mockValuesProxy = createProxyForObject(mockValues); | ||
|
||
const detectGapsAndSplit = jest.fn(UtilsImplementation.detectGapsAndSplit); | ||
|
||
const validateAndApplyDeferredUpdates = jest.fn((clientLastUpdateID?: number) => | ||
(mockValuesProxy.onValidateAndApplyDeferredUpdates === undefined ? Promise.resolve() : mockValuesProxy.onValidateAndApplyDeferredUpdates(clientLastUpdateID)).then(() => | ||
UtilsImplementation.validateAndApplyDeferredUpdates(clientLastUpdateID), | ||
), | ||
); | ||
|
||
export {applyUpdates, detectGapsAndSplit, validateAndApplyDeferredUpdates, mockValuesProxy as mockValues}; | ||
export type {OnyxUpdateManagerUtilsMock}; |
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,9 @@ | ||
// We need to keep this in a separate file, so that we can mock this function in tests. | ||
import type {DeferredUpdatesDictionary} from '@libs/actions/OnyxUpdateManager/types'; | ||
import * as OnyxUpdates from '@userActions/OnyxUpdates'; | ||
|
||
// This function applies a list of updates to Onyx in order and resolves when all updates have been applied | ||
const applyUpdates = (updates: DeferredUpdatesDictionary) => Promise.all(Object.values(updates).map((update) => OnyxUpdates.apply(update))); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export {applyUpdates}; |
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,8 @@ | ||
import type {DeferredUpdatesDictionary} from '@libs/actions/OnyxUpdateManager/types'; | ||
import createProxyForObject from '@src/utils/createProxyForObject'; | ||
|
||
const deferredUpdatesValue = {deferredUpdates: {} as DeferredUpdatesDictionary}; | ||
|
||
const deferredUpdatesProxy = createProxyForObject(deferredUpdatesValue); | ||
|
||
export default deferredUpdatesProxy; |
Oops, something went wrong.
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.
This comment was marked as resolved.
Sorry, something went wrong.