-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Improve ShouldReportBeInOptionList function #81551
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
base: main
Are you sure you want to change the base?
Improve ShouldReportBeInOptionList function #81551
Conversation
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
| if (report?.reportID === currentReportId) { | ||
| return CONST.REPORT_IN_LHN_REASONS.IS_FOCUSED; | ||
| } |
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.
| if (report?.reportID === currentReportId) { | |
| return CONST.REPORT_IN_LHN_REASONS.IS_FOCUSED; | |
| } | |
| // Include the currently viewed report. If we excluded the currently viewed report, then there | |
| // would be no way to highlight it in the options list and it would be confusing to users because they lose | |
| // a sense of context. | |
| if (report.reportID === currentReportId) { | |
| return CONST.REPORT_IN_LHN_REASONS.IS_FOCUSED; | |
| } |
can we restore the comment you moved?
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.
restored
src/libs/ReportUtils.ts
Outdated
| let parentReportActionComputed = false; | ||
| let parentReportActionCache: OnyxEntry<ReportAction>; | ||
| const getParentReportAction = (): OnyxEntry<ReportAction> => { | ||
| if (!parentReportActionComputed) { | ||
| parentReportActionComputed = true; | ||
| parentReportActionCache = isThreadReport ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined; | ||
| } | ||
| return parentReportActionCache; | ||
| }; |
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 see you are doing some kind of caching here, but I don't think how this would make significant difference as we are basically just performing a lookup in allReportActions, 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.
yes you right so I reverted this one
src/libs/ReportUtils.ts
Outdated
| if (!report.lastReadTime) { | ||
| return !isEmptyReport(report, isReportArchived); | ||
| } | ||
|
|
||
| if (isEmptyReport(report, isReportArchived)) { | ||
| return false; | ||
| } |
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.
In both ifs we check for isEmptyReport(report, isReportArchived), it looks like it can be even more simplified
| if (!report.lastReadTime) { | |
| return !isEmptyReport(report, isReportArchived); | |
| } | |
| if (isEmptyReport(report, isReportArchived)) { | |
| return false; | |
| } | |
| if (isEmptyReport(report, isReportArchived)) { | |
| return false; | |
| } | |
| if (!report.lastReadTime) { | |
| return 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.
done
src/libs/ReportUtils.ts
Outdated
| const isThreadReport = isThread(report); | ||
| let parentReportActionComputed = false; | ||
| let parentReportActionCache: OnyxEntry<ReportAction>; | ||
| const getParentReportAction = (): OnyxEntry<ReportAction> => { |
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 do not see that we use such kind on patter define function inside function.
I think it makes sense to move it out from here, pass need params and just use
const parentReportAction = getParentReportAction(parentReportActionComputed, isThreadReport, allReportActions)
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 revert this function in my commit
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.
fixed
src/libs/ReportUtils.ts
Outdated
| let parentReportActionCache: OnyxEntry<ReportAction>; | ||
| const getParentReportAction = (): OnyxEntry<ReportAction> => { | ||
| if (!parentReportActionComputed) { | ||
| parentReportActionComputed = 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.
I think it is better to change it to true after the actual operation
At this case if smth will go wrong - we do not update the flag
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.
Im not using it in my new commit
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.
fixed
JKobrynski
left a comment
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.
Left one comment, other than that LGTM
src/libs/ReportUtils.ts
Outdated
| const reportActionKeys = Object.keys(currentReportActions); | ||
|
|
||
| const isThreadReport = isThread(report); | ||
| const parentReportAction = isThreadReport ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined; |
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.
| const parentReportAction = isThreadReport ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined; | |
| const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]; | |
| const parentReportAction = isThreadReport | |
| ? parentReportActions?.[report.parentReportActionID] | |
| : undefined; |
I would consider something like this, I think it makes it more readable
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.
Sure Fixed
| const triggerUnreadUpdate = debounce(() => { | ||
| const currentReportID = navigationRef?.isReady?.() ? Navigation.getTopmostReportId() : undefined; | ||
| const draftComment = allDraftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${currentReportID}`]; | ||
| Timing.start(CONST.TIMING.GET_UNREAD_REPORTS_FOR_UNREAD_INDICATOR); |
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.
FYI the Timing module is getting deprecated here #81691
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.
let's either not track this at all, or record regular Sentry spans
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.
Ill modify my code. . btw there will be other local alternative or mostly with sentry ?
| } | ||
|
|
||
| if (isSelfDM(report)) { | ||
| if (isSelfDMReport) { |
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.
what does Opus say about these changes, is there still some room for more improvement from a static analysis of hot paths?
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.
Opus you mean the ai model right ? I used it to get the initial recommendations and while there was also more options It didn't make difference in performance and was more complex and risky than this minor changes.
|
@thesahindia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
@abdulrahuman5196 @mountiny One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8805b63ab1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@elirangoshen Each PR should have description, test/ qa section and screenshots/ videos provided before marked as ready for a review unless otherwise stated by someone internal |
|
No product review required |
Sure Ill add asap |
Done, let me know if its ok now |
|
Thanks!
Can you be more specific with this one please? ideally a numbered list of steps and verifying hte behaviour based on the changes you are making here |
|
@elirangoshen Can you please also work with Opus to analyze if there is a room to make the unit tests more robust? this method is very complex so I wonder if we actually do cover all the cases for it? |
I added through steps. |
Done I added more unit tests @mountiny |
Explanation of Change
Fixed Issues
$#81900
PROPOSAL: ShouldReportBeInOptionList improve
This pr improve
ShouldReportBeInOptionListperformance by reordering the actions to create more cheap early exists and use caching for repeatable expensive operationsTests
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Open the app in Default mode (not Focus/GSD mode).
Verify that all expected chats appear: DMs, group chats, workspace rooms, policy expense chats, task reports, expense requests.
Verify the currently viewed report is always highlighted/visible in the LHN.
Navigate between different reports and confirm the LHN selection follows correctly.
Focus Mode
Switch to Focus mode
Verify that only unread chats appear (and muted chats do NOT).
Send a message in a chat from another account, then check that it appears as unread in Focus mode.
Read the chat, and confirm it disappears from Focus mode.
Verify that a brand new report that has never been read (no lastReadTime) appears as unread in Focus mode. (This is the isUnread change.)
Currently Focused Report
In Focus mode, navigate to a report that is read (not unread).
Confirm it still appears in the LHN because it's the currently focused report.
Navigate away from it, and confirm it disappears from the LHN (since it's read and no longer focused).
Chat Threads
Open a chat thread that has replies — it should appear in the LHN.
Find an empty chat thread (no replies, just the parent message) — it should not appear in the LHN.
Delete the parent message of a thread with no replies — the thread should not appear.
Open a thread where the parent message is pending deletion — it should not appear.
Pinned Reports
Pin a report — confirm it appears in LHN in both Default and Focus modes.
Unpin it — confirm normal visibility rules apply again.
Reports with Drafts
Start typing a message in a chat (create a draft) but don't send it.
Confirm the report appears in the LHN (both modes) with the draft indicator.
Self DM
Verify the Self DM (chat with yourself) appears correctly in the LHN.
System Chat
If you have a system chat (notifications account), verify it appears correctly.
Archived Reports
Archive a report.
In Default mode, confirm it still appears in the LHN.
In Focus mode, confirm it only appears if unread.
Empty Chats
Create a new DM with someone but don't send any message.
In Default mode with excludeEmptyChats, confirm the empty chat is hidden.
Send a message — confirm it now appears.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari