-
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
Refactor Get_ReportHistory #9613
Conversation
# Conflicts: # src/libs/actions/Report.js
@marcaaron if you have some time I would appreciate a first glance at this one as well, I think I got the gist of it, but still not sure I did it right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, but a lot of changes left to make. Please let me know if there are specific questions!
src/libs/actions/Report.js
Outdated
_.each(reportIDsToFetchActions, (reportID) => { | ||
const offset = ReportActions.dangerouslyGetReportActionsMaxSequenceNumber(reportID, false); | ||
readOldestAction(reportID, offset); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these changes need to be removed. I'll try to break down everything and explain why it's incorrect...
Actions need to be tied to user actions
- We should not be calling
readOldestAction()
as a direct replacement forfetchActions()
readOldestAction()
would be called when we... read the oldest action and no other time- Reading the oldest action means that we are scrolling up on the report and new chat messages are loading
So what "action" should we use for this existing code?
- None. IIRC we decided to remove this.
- Why does it exist?
- It's an optimization (possibly not needed) used by the front end to preload a bunch of chat messages for various recent reports that we know are "missing actions" based on the locally stored actions we already have.
- Why are we using a timer? If we keep the code should it be removed?
- We run this code at a significant delay to avoid performance issues from loading too many actions at once. If we are not removing the code right now we should keep the timer.
What should we do for now?
I think just remove the code entirely is fine. If we want to "preload" actions we can think of a better design and have it hook into the big "App Start" event. Chatted about this for a bit with @luacmartins in this doc section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this, feel like once we finish the refactor, we can figure if this is still needed and if that is the case come up with a better way of doing this.
Is this one of the reasons we sometimes have a white loading page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Let's remove it and create a follow up issue to investigate.
I'm not sure about the white loading page and haven't experienced that myself - could be related or not.
src/libs/actions/Report.js
Outdated
*/ | ||
function readOldestAction(reportID, offset = 0) { | ||
const hasFinishedLoadingData = { | ||
onyxMethod: 'merge', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onyxMethod: 'merge', | |
onyxMethod: CONST.ONYX.METHOD.MERGE, |
src/libs/actions/Report.js
Outdated
* @param {Number} offset | ||
*/ | ||
function readOldestAction(reportID, offset = 0) { | ||
const hasFinishedLoadingData = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name sounds a bit like a boolean (has, should, is, etc) and we should update to defaultReportActionsLoadingState
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason at some point this became a boolean in my head, really don't know why, when is so obviously not.
src/libs/actions/Report.js
Outdated
}, | ||
}; | ||
|
||
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_ACTIONS, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_ACTIONS, true); |
src/libs/actions/Report.js
Outdated
offset, | ||
}, | ||
{ | ||
optimisticData: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimisticData: [], | |
optimisticData: [{ | |
onyxMethod: CONST.ONYX.METHOD.MERGE, | |
key: `${ONYXKEYS.IS_LOADING_REPORT_ACTIONS}${reportID}`, | |
value: {isLoading: true}, | |
}], |
src/libs/actions/Report.js
Outdated
function readOldestAction(reportID, offset = 0) { | ||
const hasFinishedLoadingData = { | ||
onyxMethod: 'merge', | ||
key: `${ONYXKEYS.IS_LOADING_REPORT_ACTIONS}${reportID}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks kind of right, but there's a more correct way to do this.
If we want to start tracking the loading status for each report in this way we would want to create a "collection" key. Explained in the features of Onyx here, but let me know if you have any questions about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would need to create a key in collections, and use that one instead? is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep you got it.
@@ -300,7 +300,7 @@ class ReportActionsView extends React.Component { | |||
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which | |||
// case just get everything starting from 0. | |||
const offset = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0); | |||
Report.fetchActionsWithLoadingState(this.props.reportID, offset); | |||
Report.readOldestAction(this.props.reportID, offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct because we are passing the "oldest action" to the API.
@@ -275,7 +275,7 @@ class ReportActionsView extends React.Component { | |||
} | |||
|
|||
fetchData() { | |||
Report.fetchActions(this.props.reportID); | |||
Report.readOldestAction(this.props.reportID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few more changes that need to happen in this file, but this one is incorrect as we are not reading the oldest action here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got it now, we need to call ReadOldestAction
in the places we are calling fetchActions
and passing an oldestAction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost... we need to call ReadOldestAction
when the user "reads the oldest action". Which is just another way of saying "pagination".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that makes sense.
I think we only have one place at the moment though
@@ -300,7 +300,7 @@ class ReportActionsView extends React.Component { | |||
// Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which | |||
// case just get everything starting from 0. | |||
const offset = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would help to rename this variable oldestActionSequenceNumber
src/libs/actions/Report.js
Outdated
|
||
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_ACTIONS, true); | ||
|
||
API.write('ReadOldestAction', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set this as Write, but I think it should be read right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hmm yes since we are not writing anything in the server I think that's correct.
src/libs/actions/Report.js
Outdated
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
}, |
# Conflicts: # src/libs/actions/App.js
remove successData for actions
Changes look good, but we are still missing...
Also we'll need a new Web-E PR with these changes -> https://github.com/Expensify/Web-Expensify/compare/marcaaron-stdClassSolution?expand=1 to fix the weird issue described in this Slack thread |
npm has a |
1 similar comment
npm has a |
this needs to hold until https://github.com/Expensify/Web-Expensify/pull/34374 is CP/merged, but it's ready otherwise |
npm has a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looking real good! Just leaving a few tiny recommended changes
package-lock.json
Outdated
"integrity": "sha1-BqZgTWpV1L9BqaR9mHLXp42jHnM=" | ||
"integrity": "sha512-xpkr6sCDIYTPqzvjG8M3ncw1YOTaloWZOyrUmicoEifBEKzQzt+ooUpRpQ/AbOoJfO/p2ZKiyp79qHThzJDulQ==" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, are we ok with committing these types of changes?
Mainly asking b/c it was recommended I don't commit these changes here: #9635 (comment)
And I think it makes sense to all agree or disagree what the best plan is 😅
cc @Julesssss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @sketchydroide is on an M1 Mac, I think it's okay right? But yeah we should clarify this rule as the changes do look similar to yours @Beamanator.
I think the idea is that anyone on an M1 Mac should not see a diff when running npm i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was commited by mistake, and @marcaaron already asked for the commit of this file to be reverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reset this
src/libs/actions/Report.js
Outdated
@@ -1160,6 +1095,37 @@ function openReport(reportID) { | |||
}); | |||
} | |||
|
|||
/** | |||
* Gets the actions from the oldest unread action. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 ReadOldestAction
is singular so we're only getting 1 action. If that's true, great - let's update this comment so it is clear we're only getting 1 action. Otherwise can we think about making the command ReadOldestActions
and clarifying if we're getting oldest unread action & newer or & older?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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?
We would need to change Web as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Both comments left have been resolved.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @marcaaron in version: 1.1.86-0 🚀
|
🚀 Deployed to production by @yuwenmemon in version: 1.1.86-5 🚀
|
CC @marcaaron - let me know if I'm going in the right direction
Details
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/212870
Tests
For this test you need a chat with over 100 actions, if more than 150 even better.
Also before starting make sure you have the latest changes from Web-Expensify pulled
PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
For this test you need a chat with over 100 actions, if more than 150 even better.
Screenshots
Web
Mobile Web
Desktop
iOS
Android