Skip to content
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

De-dupe ReconnectApp in the persisted requests queue #47913

Merged
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e388597
Updating reconnectApp from the persisted requests queue
gedu Aug 22, 2024
6f278c0
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Aug 28, 2024
615a8ba
Applying comments + unit tests
gedu Aug 29, 2024
8b505ab
Adding comment
gedu Aug 29, 2024
be72fec
Adding test to Sequential Queue
gedu Aug 30, 2024
6e40d66
Fixed TS error
gedu Aug 30, 2024
31bf286
removed the .only from test
gedu Aug 30, 2024
7f1b772
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 3, 2024
45bf5a6
Fixes and moving the ongoing request to PersistedRequests
gedu Sep 10, 2024
3620da6
Fixed APITest
gedu Sep 10, 2024
1d9550c
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 10, 2024
d07d912
Fixed tests and code
gedu Sep 11, 2024
7170e14
Fixed lint issues
gedu Sep 11, 2024
69463bb
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 13, 2024
b9d19f0
Tests to App.reconnectApp + some minors
gedu Sep 16, 2024
dc6aa40
Cleanup
gedu Sep 17, 2024
2f0e209
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 17, 2024
b6b893b
Fixed some deprecated eslints
gedu Sep 17, 2024
1fcd87d
Rolling back change
gedu Sep 17, 2024
b9cb098
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 17, 2024
3b21e41
disable deprecation fields
gedu Sep 17, 2024
919e254
Removed hack, seems we don't need it anymore
gedu Sep 18, 2024
1c5c49b
Removed unused key
gedu Sep 18, 2024
9ff5edd
Added the chance to save the ongoing request into Onyx for later proc…
gedu Sep 24, 2024
d3bf574
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 24, 2024
2bc9f32
fixed eslint error
gedu Sep 24, 2024
4b309bf
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 25, 2024
cae7b49
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 26, 2024
2792cfe
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Sep 27, 2024
703957d
Fixed comments
gedu Sep 27, 2024
7d90d66
replaced with unshift
gedu Sep 27, 2024
1e0d4ed
removed duplicated rule
gedu Oct 1, 2024
ccadfd6
Merge branch 'main' into gedu/replace_reconnectapp_most_updated
gedu Oct 2, 2024
0877308
Fixed some eslint issues
gedu Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/libs/actions/PersistedRequests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import isEqual from 'lodash/isEqual';
import Onyx from 'react-native-onyx';
import {WRITE_COMMANDS} from '@libs/API/types';
import Log from '@libs/Log';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Request} from '@src/types/onyx';

let persistedRequests: Request[] = [];
const keepLastInstance: string[] = [WRITE_COMMANDS.RECONNECT_APP];

Onyx.connect({
key: ONYXKEYS.PERSISTED_REQUESTS,
Expand All @@ -23,9 +25,22 @@ function getLength(): number {
}

function save(requestToPersist: Request) {
const requests = [...persistedRequests, requestToPersist];
persistedRequests = requests;
Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, requests).then(() => {
if (keepLastInstance.includes(requestToPersist.command)) {
// Find the index of an existing request with the same command
const index = persistedRequests.findIndex((request) => request.command === requestToPersist.command);

if (index !== -1) {
// If found, update the existing request with the new one
persistedRequests[index] = requestToPersist;
} else {
// If not found, add the new request
persistedRequests.push(requestToPersist);
}
} else {
// If the command is not in the keepLastInstance array, add the new request as usual
persistedRequests = [...persistedRequests, requestToPersist];
}
Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests).then(() => {
Log.info(`[SequentialQueue] '${requestToPersist.command}' command queued. Queue length is ${getLength()}`);
});
}
Expand Down
Loading