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

Make sure all reports are included when fetching all reports #600

Closed
wants to merge 1 commit into from

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Oct 6, 2020

Possible fix for #597 to ensure we have all the reports

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but still not 100% sure why/if we need this

Also, one thing that is bugging me is that if we look at the code here we're setting the value of the report (which would now include chat reports):
https://github.com/Expensify/ReactNativeChat/blob/dc4ecb810d228c8c61467680051eba68e6ff425e/src/lib/actions/Report.js#L315-L318

But we've already done this for the chat reports when fetching them on their own here:
https://github.com/Expensify/ReactNativeChat/blob/dc4ecb810d228c8c61467680051eba68e6ff425e/src/lib/actions/Report.js#L150-L159

I haven't identified a problem with that per se, but since this is not happening synchronously anymore I wonder if we could get some weird data or missing reportName from this change? The order of operations is a little unclear. At the very least, we are setting report data in Ion twice whenever fetching. Again, not sure if this is a problem just creates "another thing to think about".

@@ -158,6 +158,7 @@ function fetchChatReportsByIDs(chatList) {
// Merge the data into Ion
Ion.merge(`${IONKEYS.COLLECTION.REPORT}${report.reportID}`, newReport);
});
return {reports: _.indexBy(fetchedReports, 'reportID')};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe fetchedReports is already an object indexed by reportID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, maybe

@@ -290,14 +291,19 @@ function fetchAll(shouldRedirectToFirstReport = true, shouldFetchActions = false

promiseAllSettled(reportFetchPromises)
.then((data) => {
fetchedReports = _.compact(_.map(data, (promiseResult) => {
fetchedReports = _.compact(_.reduce(data, (finalArray, promiseResult) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need compact if we're changing this to reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@tgolen
Copy link
Contributor Author

tgolen commented Oct 6, 2020

But we've already done this for the chat reports when fetching them on their own here:

That's a great point. I hadn't considered that these reports are being double-merged into Ion. Perhaps in this case then, it's better to do what I mentioned in your PR and to refactor reportFetchPromises.push(fetchChatReports()); so that we stop worrying about those promises and the data returned from them.

@tgolen
Copy link
Contributor Author

tgolen commented Oct 6, 2020

OK, I'm just going to close this for now and look forward to the changes in your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants