Skip to content

Commit

Permalink
revert: cache last 5 reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed May 8, 2024
1 parent 8fda27f commit c7f128b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
21 changes: 2 additions & 19 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,11 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp
return;
}

const lastUpdatedReports = ReportUtils.getLastUpdatedReports();

if (!lastUpdatedReports.length) {
return;
}
const newReports = OptionsListUtils.createOptionList({}, reports).reports;

setOptions((prevOptions) => {
const newOptions = {...prevOptions};
lastUpdatedReports.forEach((lastUpdatedReport) => {
if (!lastUpdatedReport) {
return;
}

const newOption = OptionsListUtils.createOptionFromReport(lastUpdatedReport, personalDetails);
const replaceIndex = options.reports.findIndex((option) => option.reportID === lastUpdatedReport.reportID);

if (replaceIndex === -1) {
return;
}

newOptions.reports[replaceIndex] = newOption;
});
newOptions.reports = newReports;
return newOptions;
});
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
14 changes: 5 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,7 @@ Onyx.connect({
},
});

const MAX_UPDATE_DEPTH = 5;
const lastUpdatedReports: Array<OnyxEntry<Report>> = [];
let lastUpdatedReport: OnyxEntry<Report>;

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand All @@ -580,15 +579,12 @@ Onyx.connect({
return;
}

if (lastUpdatedReports.length >= MAX_UPDATE_DEPTH) {
lastUpdatedReports.shift();
}
lastUpdatedReports.push(value);
lastUpdatedReport = value;
},
});

function getLastUpdatedReports(): Array<OnyxEntry<Report>> {
return lastUpdatedReports;
function getLastUpdatedReport(): OnyxEntry<Report> {
return lastUpdatedReport;
}

function getCurrentUserAvatarOrDefault(): UserUtils.AvatarSource {
Expand Down Expand Up @@ -6597,7 +6593,7 @@ export {
getIcons,
getIconsForParticipants,
getIndicatedMissingPaymentMethod,
getLastUpdatedReports,
getLastUpdatedReport,
getLastVisibleMessage,
getMoneyRequestOptions,
getMoneyRequestSpendBreakdown,
Expand Down

0 comments on commit c7f128b

Please sign in to comment.