-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Refactor Get_ReportHistory #9613
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
Changes from 34 commits
f2f4740
963fcc9
9777a88
9bcfda0
ff8bb0f
bdc16db
926d388
1f6fbe4
0a0cf9a
3fffea6
01269a3
72e896e
55835a6
ef81dbb
7ba25f1
c6b0ccc
4e01c35
4a3bcd3
38e73a3
ff7cd6b
0d66a1f
dd5d4b6
8b17188
3f06e7a
2740fde
dc1cf4c
65bf517
24d7b31
61354ef
5287bc7
9f3fab1
d829272
0eece64
92ddb4a
17769b9
a3592e2
048751d
00e0dba
700792a
92c619e
b9e84f6
ec6c141
a016a61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,7 +21,6 @@ import CONST from '../../CONST'; | |||||
import Log from '../Log'; | ||||||
import * as LoginUtils from '../LoginUtils'; | ||||||
import * as ReportUtils from '../ReportUtils'; | ||||||
import Timers from '../Timers'; | ||||||
import * as ReportActions from './ReportActions'; | ||||||
import Growl from '../Growl'; | ||||||
import * as Localize from '../Localize'; | ||||||
|
@@ -691,11 +690,10 @@ function fetchOrCreateChatReport(participants, shouldNavigate = true) { | |||||
* Get the actions of a report | ||||||
* | ||||||
* @param {Number} reportID | ||||||
* @param {Number} [offset] | ||||||
* @returns {Promise} | ||||||
*/ | ||||||
function fetchActions(reportID, offset) { | ||||||
const reportActionsOffset = !_.isUndefined(offset) ? offset : -1; | ||||||
function fetchActions(reportID) { | ||||||
const reportActionsOffset = -1; | ||||||
|
||||||
if (!_.isNumber(reportActionsOffset)) { | ||||||
Log.alert('[Report] Offset provided is not a number', { | ||||||
|
@@ -720,28 +718,14 @@ function fetchActions(reportID, offset) { | |||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Get the actions of a report | ||||||
* | ||||||
* @param {Number} reportID | ||||||
* @param {Number} [offset] | ||||||
*/ | ||||||
function fetchActionsWithLoadingState(reportID, offset) { | ||||||
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_ACTIONS, true); | ||||||
fetchActions(reportID, offset) | ||||||
.finally(() => Onyx.set(ONYXKEYS.IS_LOADING_REPORT_ACTIONS, false)); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Get all of our reports | ||||||
* | ||||||
* @param {Boolean} shouldRecordHomePageTiming whether or not performance timing should be measured | ||||||
* @param {Boolean} shouldDelayActionsFetch when the app loads we want to delay the fetching of additional actions | ||||||
* @returns {Promise} | ||||||
*/ | ||||||
function fetchAllReports( | ||||||
shouldRecordHomePageTiming = false, | ||||||
shouldDelayActionsFetch = false, | ||||||
) { | ||||||
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_DATA, true); | ||||||
return DeprecatedAPI.Get({ | ||||||
|
@@ -776,47 +760,6 @@ function fetchAllReports( | |||||
if (shouldRecordHomePageTiming) { | ||||||
Timing.end(CONST.TIMING.HOMEPAGE_REPORTS_LOADED); | ||||||
} | ||||||
|
||||||
// Delay fetching report history as it significantly increases sign in to interactive time. | ||||||
// Register the timer so we can clean it up if the user quickly logs out after logging in. If we don't | ||||||
// cancel the timer we'll make unnecessary API requests from the sign in page. | ||||||
Timers.register(setTimeout(() => { | ||||||
// Filter reports to see which ones have actions we need to fetch so we can preload Onyx with new | ||||||
// content and improve chat switching experience by only downloading content we don't have yet. | ||||||
// This improves performance significantly when reconnecting by limiting API requests and unnecessary | ||||||
// data processing by Onyx. | ||||||
const reportIDsWithMissingActions = _.chain(returnedReports) | ||||||
.map(report => report.reportID) | ||||||
.filter(reportID => ReportActions.isReportMissingActions(reportID, lodashGet(allReports, [reportID, 'maxSequenceNumber']))) | ||||||
.value(); | ||||||
|
||||||
// Once we have the reports that are missing actions we will find the intersection between the most | ||||||
// recently accessed reports and reports missing actions. Then we'll fetch the history for a small | ||||||
// set to avoid making too many network requests at once. | ||||||
const reportIDsToFetchActions = _.chain(ReportUtils.sortReportsByLastVisited(allReports)) | ||||||
.map(report => report.reportID) | ||||||
.reverse() | ||||||
.intersection(reportIDsWithMissingActions) | ||||||
.slice(0, 10) | ||||||
.value(); | ||||||
|
||||||
if (_.isEmpty(reportIDsToFetchActions)) { | ||||||
Log.info('[Report] Local reportActions up to date. Not fetching additional actions.'); | ||||||
return; | ||||||
} | ||||||
|
||||||
Log.info('[Report] Fetching reportActions for reportIDs: ', false, { | ||||||
reportIDs: reportIDsToFetchActions, | ||||||
}); | ||||||
_.each(reportIDsToFetchActions, (reportID) => { | ||||||
const offset = ReportActions.dangerouslyGetReportActionsMaxSequenceNumber(reportID, false); | ||||||
fetchActions(reportID, offset); | ||||||
}); | ||||||
|
||||||
// We are waiting a set amount of time to allow the UI to finish loading before bogging it down with | ||||||
// more requests and operations. Startup delay is longer since there is a lot more work done to build | ||||||
// up the UI when the app first initializes. | ||||||
}, shouldDelayActionsFetch ? CONST.FETCH_ACTIONS_DELAY.STARTUP : CONST.FETCH_ACTIONS_DELAY.RECONNECT)); | ||||||
}); | ||||||
} | ||||||
|
||||||
|
@@ -1132,6 +1075,45 @@ function openReport(reportID) { | |||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets the actions from the oldest unread action. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we clarify: Does this get actions from the oldest unread action and older? or and newer? Not sure if my proposed addition is 100% clear even, but just from reading this I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this reads in to the older actions/messages, basically when you scroll up, so older and older There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about the plural part though. @marcaaron do you have thoughts on that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We (the user) are reading the "oldest action". This is synonymous with scrolling up to the oldest action stored locally - a.k.a. triggering a call to paginate the actions and load the next set. It should not be plural and we are not "only getting 1 action" we are getting the next set of historical actions. |
||||||
* | ||||||
* @param {Number} reportID | ||||||
* @param {Number} oldestActionSequenceNumber | ||||||
*/ | ||||||
function readOldestAction(reportID, oldestActionSequenceNumber) { | ||||||
API.read('ReadOldestAction', | ||||||
{ | ||||||
reportID, | ||||||
reportActionsOffset: oldestActionSequenceNumber, | ||||||
}, | ||||||
{ | ||||||
optimisticData: [{ | ||||||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||||||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||||||
value: {isLoading: true}, | ||||||
}], | ||||||
successData: [ | ||||||
{ | ||||||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||||||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||||||
value: { | ||||||
isLoading: false, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
], | ||||||
failureData: [{ | ||||||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||||||
key: `${ONYXKEYS.COLLECTION.IS_LOADING_REPORT_ACTIONS}${reportID}`, | ||||||
value: {isLoading: false}, | ||||||
}], | ||||||
}); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets the IOUReport and the associated report actions. | ||||||
* | ||||||
|
@@ -1655,12 +1637,12 @@ export { | |||||
navigateToConciergeChat, | ||||||
handleInaccessibleReport, | ||||||
setReportWithDraft, | ||||||
fetchActionsWithLoadingState, | ||||||
createPolicyRoom, | ||||||
renameReport, | ||||||
setIsComposerFullSize, | ||||||
markCommentAsUnread, | ||||||
readNewestAction, | ||||||
readOldestAction, | ||||||
openReport, | ||||||
openPaymentDetailsPage, | ||||||
}; |
Uh oh!
There was an error while loading. Please reload this page.