From 6c272587c5f54b2578aed4e867c0a1a0be3a97e5 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 6 May 2021 16:18:30 -1000 Subject: [PATCH 1/2] Limit initial fetch of report history to 10 recently accessed reports --- src/libs/actions/Report.js | 14 ++++++++++++-- src/libs/reportUtils.js | 20 +++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 8f2f712e89dc..e138b33445bf 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -17,7 +17,7 @@ import Timing from './Timing'; import * as API from '../API'; import CONST from '../../CONST'; import Log from '../Log'; -import {isReportMessageAttachment} from '../reportUtils'; +import {isReportMessageAttachment, sortReportsByLastVisited} from '../reportUtils'; import Timers from '../Timers'; import {dangerouslyGetReportActionsMaxSequenceNumber, isReportMissingActions} from './ReportActions'; @@ -811,10 +811,20 @@ function fetchAllReports( // 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 reportIDsToFetchActions = _.filter(returnedReportIDs, id => ( + const reportIDsWithMissingActions = _.filter(returnedReportIDs, id => ( isReportMissingActions(id, reportMaxSequenceNumbers[id]) )); + // 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(sortReportsByLastVisited(allReports)) + .map(report => report.reportID) + .reverse() + .intersection(reportIDsWithMissingActions) + .slice(0, 10) + .value(); + if (_.isEmpty(reportIDsToFetchActions)) { console.debug('[Report] Local reportActions up to date. Not fetching additional actions.'); return; diff --git a/src/libs/reportUtils.js b/src/libs/reportUtils.js index b46e3acfe60b..237b9519cc34 100644 --- a/src/libs/reportUtils.js +++ b/src/libs/reportUtils.js @@ -22,22 +22,32 @@ function isReportMessageAttachment(reportMessageText) { } /** - * Given a collection of reports returns the most recently accessed one + * Given a collection of reports returns them sorted by last visited * - * @param {Record|Array<{lastVisitedTimestamp, reportID}>} reports - * @returns {Object} + * @param {Object} reports + * @returns {Array} */ -function findLastAccessedReport(reports) { +function sortReportsByLastVisited(reports) { return _.chain(reports) .toArray() .filter(report => report && report.reportID) .sortBy('lastVisitedTimestamp') - .last() .value(); } +/** + * Given a collection of reports returns the most recently accessed one + * + * @param {Record|Array<{lastVisitedTimestamp, reportID}>} reports + * @returns {Object} + */ +function findLastAccessedReport(reports) { + return _.last(sortReportsByLastVisited(reports)); +} + export { getReportParticipantsTitle, isReportMessageAttachment, findLastAccessedReport, + sortReportsByLastVisited, }; From d95d8da660ca6fc0acb2f7fdbe2f0192a8600f30 Mon Sep 17 00:00:00 2001 From: OSBotify Date: Wed, 26 May 2021 16:25:48 +0000 Subject: [PATCH 2/2] Update version to 1.0.54-3 --- android/app/build.gradle | 4 ++-- ios/ExpensifyCash/Info.plist | 2 +- ios/ExpensifyCashTests/Info.plist | 2 +- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 8bd99bdb5c00..4c3d84711746 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -148,8 +148,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion multiDexEnabled rootProject.ext.multiDexEnabled - versionCode 1001005402 - versionName "1.0.54-2" + versionCode 1001005403 + versionName "1.0.54-3" } splits { abi { diff --git a/ios/ExpensifyCash/Info.plist b/ios/ExpensifyCash/Info.plist index 9094ff7ed2b0..1f100f5731c3 100644 --- a/ios/ExpensifyCash/Info.plist +++ b/ios/ExpensifyCash/Info.plist @@ -30,7 +30,7 @@ CFBundleVersion - 1.0.54.2 + 1.0.54.3 ITSAppUsesNonExemptEncryption LSApplicationQueriesSchemes diff --git a/ios/ExpensifyCashTests/Info.plist b/ios/ExpensifyCashTests/Info.plist index e43942f05e0d..6171983614c0 100644 --- a/ios/ExpensifyCashTests/Info.plist +++ b/ios/ExpensifyCashTests/Info.plist @@ -19,6 +19,6 @@ CFBundleSignature ???? CFBundleVersion - 1.0.54.2 + 1.0.54.3 diff --git a/package-lock.json b/package-lock.json index aabebe8fc009..f208bad3db8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "expensify.cash", - "version": "1.0.54-2", + "version": "1.0.54-3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c9062075f835..3aceb17aa5b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "expensify.cash", - "version": "1.0.54-2", + "version": "1.0.54-3", "author": "Expensify, Inc.", "homepage": "https://expensify.cash", "description": "Expensify.cash is the next generation of Expensify: a reimagination of payments based atop a foundation of chat.",