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

[HOLD for payment 2025-01-02][LHN Mismatch] Move client-only keys from report_ to reportMetadata_ #51867

Open
puneetlath opened this issue Nov 1, 2024 · 87 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production NewFeature Something to build that is a new item. Weekly KSv2

Comments

@puneetlath
Copy link
Contributor

puneetlath commented Nov 1, 2024

We are going to be changing the behavior of OpenApp/ReconnectApp when it does a full reconnect to replace the full reports list that the client has stored instead of merging with it. This means that any client-only data that we have about reports can potentially get wiped when the back-end reconnects.

We already have a reportMetadata_ object in Onyx that is meant to store such data. Let's move any keys that are currently client-only that are stored in the report_ object to the reportMetadata_ object. These are some likely keys that we will need to migrate:

  1. avatarFileName: The filename of the avatar.
  2. icons: List of icons for report participants.
  3. isPolicyExpenseChat: Indicates whether the report is a policy expense chat.
  4. lastMessageTimestamp: The timestamp of the last message on the report.
  5. lastReadCreated: The time of the last read of the report.
  6. openOnAdminRoom: If the admin room should be opened.
  7. cachedTotal: Report cached total.
  8. lastMessageTranslationKey: Translation key of the last message in the report.
  9. isOptimisticReport: Whether the current report is optimistic.
  10. displayName: Display name of the report, shown in options and mentions.
  11. ownerEmail: E-mail of the report owner.
  12. errors: Collection of errors to be shown to the user.
  13. isLastMessageDeletedParentAction: Whether the last message was a deleted parent action.
  14. iouReportAmount: Total amount of money owed for IOU report.
  15. preexistingReportID: The ID of the preexisting report.
  16. isHidden: Whether the report is hidden from the options list.
  17. isChatRoom: Whether the report is a chat room.
  18. participantsList: Collection of participants' personal details.
  19. text: Text to be displayed in the options list, which matches reportName by default.
  20. privateNotes: Collection of participant private notes, indexed by their accountID.
  21. isLoadingPrivateNotes: Whether participants' private notes are currently loading.
  22. selected: Whether the report is currently selected in the options list.
  23. pendingChatMembers: Pending members of the report.
  24. transactionThreadReportID: The ID of the single transaction thread report associated with this report, if one exists.
  25. participantAccountIDs: Participant account IDs.
  26. visibleChatMemberAccountIDs: Visible chat member account IDs.

To do this we will need to:

  1. Confirm whether this is the complete list of keys to migrate or whether there are others
  2. Confirm whether these keys all need to exist. Some of them seem like they might potentially be redundant and could be removed altogether. For example, isPolicyExpenseChat and isChatRoom seem like they may be redundant with chatType. The ownerEmail seems like it may be redundant with ownerAccountID. We should check each key and ensure that it's actually needed.
  3. For those that are needed, let's move them to reportMetadata_ by:
    a. Updating any code that sets the data to set it in reportMetadata_ instead
    b. Updating any code that gets the data to get it from reportMetadata_ instead
    c. Create migration to migrate any existing data in these keys from report_ to reportMetadata_
  4. Let's make it so that people can't accidentally add new client-only keys to the report object. We can do this by adding a unit test that checks that only these keys have been added to the report object. So that it must be explicitly updated if new keys are added after confirming that they are safe to add there
Issue OwnerCurrent Issue Owner: @muttmuure
@puneetlath puneetlath added Daily KSv2 NewFeature Something to build that is a new item. labels Nov 1, 2024
@puneetlath puneetlath self-assigned this Nov 1, 2024
Copy link

melvin-bot bot commented Nov 1, 2024

Current assignee @puneetlath is eligible for the NewFeature assigner, not assigning anyone new.

@melvin-bot melvin-bot bot added the Weekly KSv2 label Nov 1, 2024
Copy link

melvin-bot bot commented Nov 1, 2024

⚠️ It looks like this issue is labelled as a New Feature but not tied to any GitHub Project. Keep in mind that all new features should be tied to GitHub Projects in order to properly track external CAP software time ⚠️

@melvin-bot melvin-bot bot removed the Daily KSv2 label Nov 1, 2024
Copy link

melvin-bot bot commented Nov 1, 2024

Triggered auto assignment to Design team member for new feature review - @dubielzyk-expensify (NewFeature)

@puneetlath puneetlath changed the title Move client-only keys from report_ to reportMetadata_ [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Nov 1, 2024
@puneetlath puneetlath moved this to CRITICAL in [#whatsnext] #quality Nov 1, 2024
@puneetlath
Copy link
Contributor Author

Confirm whether this is the complete list of keys to migrate or whether there are others

I'll be taking this part since it requires looking at the back-end also.

@TMisiukiewicz
Copy link
Contributor

Hey, Tomasz from Callstack here, I can help with this issue

@puneetlath
Copy link
Contributor Author

@TMisiukiewicz I need to confirm the full list that we're working with. To start, can you look into:

  • Why do we have isPolicyExpenseChat? It seems redundant with type/chatType
  • Why do we have isChatRoom? It seems redundant with type/chatType
  • Whether there are others in the list above that seem redundant with existing data

@TMisiukiewicz
Copy link
Contributor

@puneetlath I checked this list and seems like majority of these properties are generated in the runtime and describe the options for LHN, not reports directly. Seems like they are not stored in Onyx at all, might the Report type be outdated? I think it'd be good to actually go through the properties defined in a type and verify if they are still used anywhere in the project.

So, I'd say both properties are replaceable by referring to chatType when it comes to LHN options, but I don't see those stuff being moved from report to reportMetadata since they are not stored in Onyx

@puneetlath
Copy link
Contributor Author

Oh wow, ok that's great to know.

I think it'd be good to actually go through the properties defined in a type and verify if they are still used anywhere in the project.

This makes sense to me. Want to do this as a first step? Basically, raise a PR to update the type with only the things that are actually used by the client.

Also, if the back-end attempts to merge something into Onyx that isn't in the type, do we log that?

@TMisiukiewicz
Copy link
Contributor

This makes sense to me. Want to do this as a first step? Basically, raise a PR to update the type with only the things that are actually used by the client.

yeah sure, I'll start exploring it tomorrow 👍

@TMisiukiewicz
Copy link
Contributor

TMisiukiewicz commented Nov 6, 2024

So i verified all the properties and looks like there is 15 of them that should be possible to remove:

  • icons
  • lastMessageTimestamp
  • lastReadCreated
  • isPolicyExpenseChat
  • openOnAdminRoom
  • displayName
  • errors
  • isLastMessageDeletedParentAction
  • iouReportAmount
  • isChatRoom
  • participantsList
  • text
  • selected
  • participantAccountIDs
  • visibleChatMemberAccountIDs

I’ll remove each unused property along with its references, one at a time, committing after each change to ensure stability.

@puneetlath
Copy link
Contributor Author

Nice! Sounds good. Perhaps we should break it up into a few different PRs so that it's easier to revert if one of them causes a problem, without needing to revert it all.

@TMisiukiewicz
Copy link
Contributor

Sure, i'll start with a PR with those that are not used anywhere as it's the easiest one

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Nov 7, 2024
@TMisiukiewicz
Copy link
Contributor

TMisiukiewicz commented Nov 7, 2024

Opened first PR #52182, now I'll move to work on the properties that have some references in the codebase but do not seem to be a part of Report

@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-12-17] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ [HOLD for payment 2024-12-19] [HOLD for payment 2024-12-17] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Dec 12, 2024
Copy link

melvin-bot bot commented Dec 12, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.74-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-12-19. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 12, 2024

BugZero Checklist: The PR adding this new feature has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@shubham1206agra] Please propose regression test steps to ensure the new feature will work correctly on production in further releases.
  • [@muttmuure] Link the GH issue for creating/updating the regression test once above steps have been agreed upon.

@TMisiukiewicz
Copy link
Contributor

@puneetlath just a quick heads-up, I tried building a simple, basic schema validator, just to validate simplest possible keys during set and merge.

image

I'll try to set this up with collections to be able to verify the performance overhead

@puneetlath
Copy link
Contributor Author

I moved it to reportMetadata, however while working on it, I noticed it's another key that is used by createOption so it will make an additional call to Onyx for each report. I'll try to figure out if there is a good solution for that and what is the performance impact of such change

Sounds good.

I guess this might be used to display common.attachment translation in the LHN optimistically, however I haven't been able to reproduce it's usage. When I add an attachment, first it displays file name in the LHN, and then changes for [Attachment]. Maybe it's worth digging deeper and verifying if we need this property at all.

Good to know! It would be awesome if it turns out we can remove lastMessageTranslationKey altogether.

@puneetlath just a quick heads-up, I tried building a simple, basic schema validator, just to validate simplest possible keys during set and merge.
I'll try to set this up with collections to be able to verify the performance overhead

Very cool! Interested to see what you find!

@TMisiukiewicz
Copy link
Contributor

Quick heads-up, I already implemented a simple solution for validating collection schema. Now I am measuring performance of moving pendingChatMembers to metadata and validating collections

@TMisiukiewicz
Copy link
Contributor

Moving pendingChatMembers - I ran createOptionList on HT account which is going through all the reports and now hitting the reportMetadata - I got pretty much the same results on Android so seems like it does not affect its execution time. I also ran Reassure tests locally and I got some significant changes:

 - [ReportActionsList] should render ReportActionsList with 500 reportActions stored [render]: 75.1 ms → 87.7 ms ( 12.6 ms,  16.8%) 🔴 | 1 → 1 
 - SidebarUtils [SidebarUtils] getOrderedReportIDs on 15k reports for GSD priorityMode [function]: 217.0 ms → 229.6 ms ( 12.5 ms,  5.8%) 🔴 | 1 → 1 
 - SidebarLinks [SidebarLinks] should render Sidebar with 500 reports stored [render]: 62.6 ms → 75.0 ms ( 12.4 ms,  19.8%) 🔴 | 8 → 8 
 - SidebarUtils [SidebarUtils] getOrderedReportIDs on 15k reports for default priorityMode [function]: 231.4 ms → 239.5 ms ( 8.1 ms,  3.5%)  | 1 → 1 
 - SidebarLinks [SidebarLinks] should click on list item [render]: 61.2 ms → 68.0 ms ( 6.8 ms,  11.1%) 🔴 | 9 → 9 
 - [SelectionList] should render multiple selection and select 3 items [render]: 73.2 ms → 79.9 ms ( 6.7 ms,  9.2%) 🔴 | 8 → 8 
 - [BaseOptionsList] Should scroll and select a few items [render]: 73.4 ms → 79.5 ms ( 6.1 ms,  8.3%) 🔴 | 14 → 14 
 - [BaseOptionsList] Should render multiple selection and select 4 items [render]: 64.5 ms → 68.6 ms ( 4.1 ms,  6.4%) 🔴 | 13 → 13 
 - [SelectionList] should press a list item [render]: 44.8 ms → 48.8 ms ( 4.0 ms,  8.9%) 🔴 | 4 → 4 

They do not look very scary, it's mostly a matter of milliseconds. CI can give different results. I'll work on a migration file and open a PR

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Dec 17, 2024
@TMisiukiewicz
Copy link
Contributor

Opened PR for pendingChatMembers: #54247

@TMisiukiewicz
Copy link
Contributor

Hmm if I haven't missed anything, lastMessageTranslationKey is used only for common.attachment as I said earlier. I think it should be fine to remove it, I'll work on opening a PR

@TMisiukiewicz
Copy link
Contributor

opened #54295

Copy link

melvin-bot bot commented Dec 19, 2024

Payment Summary

Upwork Job

BugZero Checklist (@muttmuure)

  • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
  • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants//hired)
  • I have paid out the Upwork contracts or cancelled the ones that are incorrect
  • I have verified the payment summary above is correct

@puneetlath
Copy link
Contributor Author

@muttmuure we've had a lot of PRs here and we're almost to the end. I think we can pay it all out in one batch to Shubham at the end.

@TMisiukiewicz
Copy link
Contributor

@puneetlath I did some performance measurements for runtime validation.

What I did was:

  • implementing basic schema validation in Onyx for one boolean key and for one collection
  • extended init command with two new properties: schema, responsible for defining schema and onSchemaError, to be able to e.g. use it with Logger
  • connected schema validation with merge and set methods

I did measurements for calling merge on report_ key on iOS and web, here are the results for iOS:

Payload Without validation With validation Difference
{} 0.00708317756652832 0.45337486267089844 64x
{"lastReadTime": "2024-12-24 08:05:37.507"} 0.010667085647583008 0.045874834060668945 4,3x
full report 0.011040925979614258 0.12216591835021973 11x

Seems like enabling it makes single merge calls much slower. I assume when calling multiple merge/set calls at the same time/using multiSet it might look the same.

Some other thoughts about it after building PoC:

  • we could do this incrementally (key by key), but for more complex keys (like report), we have to implement them entirely per PR. Otherwise it will throw errors because app is trying to merge properties that does not exist in schema
  • this might be a good tool to find out discrepancies between types. After implementing I found out that lastActorAccountID expects a string but got number when I'm trying to send a message
  • the worst part is that I haven't found any tool that would help us automatically generate schemas based on our types. Ts-to-zod that I mentioned earlier does not support generics so it won't help. There is one more alternative that I could possibly investigate which is https://github.com/vega/ts-json-schema-generator . If not this one, it would mean we have to write all the schemas on our own and then maintain them. This seems like something very time-consuming.

If you want to test it on your own, you can check my fork of Exfy with onyx-schema branch: main...TMisiukiewicz:Expensify-App:onyx-schema together with react-native-onyx branch: Expensify/react-native-onyx@main...callstack-internal:react-native-onyx:onyx-schema

Let me know your thoughts 👀 FYI I'll be mostly OOO during the upcoming two weeks, I'll be back just for one day on December 30th.

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Dec 26, 2024
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-12-19] [HOLD for payment 2024-12-17] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ [HOLD for payment 2025-01-02] [HOLD for payment 2024-12-19] [HOLD for payment 2024-12-17] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Dec 26, 2024
Copy link

melvin-bot bot commented Dec 26, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 26, 2024
Copy link

melvin-bot bot commented Dec 26, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.78-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-01-02. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Dec 26, 2024

BugZero Checklist: The PR adding this new feature has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@shubham1206agra] Please propose regression test steps to ensure the new feature will work correctly on production in further releases.
  • [@muttmuure] Link the GH issue for creating/updating the regression test once above steps have been agreed upon.

@puneetlath puneetlath changed the title [HOLD for payment 2025-01-02] [HOLD for payment 2024-12-19] [HOLD for payment 2024-12-17] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ [HOLD for payment 2025-01-02][LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Dec 26, 2024
Copy link

melvin-bot bot commented Dec 27, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production NewFeature Something to build that is a new item. Weekly KSv2
Projects
Status: CRITICAL
Development

No branches or pull requests

6 participants