-
Notifications
You must be signed in to change notification settings - Fork 3.2k
After revert: Defer local updates if there are missing updates and only call GetMissingOnyxMessages
once
#39683
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
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…
1a8528c
remove queue clearing and add TS type guard for OnyxUpdate
e52db00
fix: type check
2e13b36
simplify code
4fbbd9a
simplify code
9eaa455
fix: and simplify
c134283
add comment
36c9ad6
rename variables
c34337f
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
48fa52e
remove unnecessary pause
beb16a3
check for isLoadingApp and ActiveClientManager first
1d396e1
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
5f1bb97
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
4cdaf5d
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
26ded32
minor improvements of OnyxUpdateMangaer
e21abf5
implement tests
cbe2d9f
add exports for testing
2a29079
fix: test implementation
28004cb
implement proxy for OnyxUpdateManager
70e428e
update tests
0890696
extract util logic from OnyxUpdateManager
909b5a8
extract createProxyForValue and further split up utils
c502513
fix: tests
001eb3a
extract mocks from test
4eaf83a
apply updaes
9910943
remove unnecessary promise trigger code
b078cfa
update tests and mocks
cf3b7e6
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
2c50853
fix: ts
3904ef4
fix: tests
abff1aa
move specific mocks to mock folders
39387f6
fix: update mocks and tests
6327968
simplify
b0a70ba
fix: update mocks, tests and test utils to allow for broader E2E tests
d0e3b68
add more tests and comments
52ad15a
remove waitForBatchedChanges
a7aac11
rename and move helper function
95fc4f6
add isPaused checker function to SequentialQueue
3e8bc28
reset more things before each test
5e42e99
add another test
f57a149
fix: first test
0bb6a51
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
a738a51
remove unused line
23eab2d
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
f48d931
Merge branch 'main' into @chrispader/GetMissingOnyxMessages-deferred-…
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 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
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,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 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,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 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,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 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,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 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,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.
Uh oh!
There was an error while loading. Please reload this page.