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

[LHN Mismatch] Move client-only keys from report_ to reportMetadata_ #51867

Open
puneetlath opened this issue Nov 1, 2024 · 25 comments
Open
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: @puneetlath
@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
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 added Weekly KSv2 and removed Weekly KSv2 labels Nov 8, 2024
@TMisiukiewicz
Copy link
Contributor

Opened another PR to remove isPolicyExpenseChat. Also turned the list from the last comment into checklist to track the progress of the cleanup

@TMisiukiewicz
Copy link
Contributor

Opened last PR with unused properties. The two remaining on the list are:

Is it possible that Report had different shape in the past and it's valid only for some old reports? Maybe we should leave these properties?

@puneetlath
Copy link
Contributor Author

Ah interesting. Let me see if I can find any place where they get set from the back-end.

@puneetlath
Copy link
Contributor Author

I don't see report.errors or report.displayName as being returned from the back-end anywhere. So I think it should be safe to remove. Do you agree @shubham1206agra?

Also, @TMisiukiewicz do we log if someone tries to set an Onyx field that isn't part of the report Onyx type? And if not, could we?

@shubham1206agra
Copy link
Contributor

@TMisiukiewicz displayName is being used to store the calculated displayName in LHN. Can you confirm this?

@TMisiukiewicz
Copy link
Contributor

@shubham1206agra yeah they are used to calulate the display name for LHN, but they are not stored in Onyx

@TMisiukiewicz
Copy link
Contributor

Also, @TMisiukiewicz do we log if someone tries to set an Onyx field that isn't part of the report Onyx type? And if not, could we?

I think we have only static checks (Typescript). Do you have anything particular in your mind? If yes, how do you think it should work?

@shubham1206agra
Copy link
Contributor

Hey
This variable is most probably used as typecheck there. Just fix that

@TMisiukiewicz
Copy link
Contributor

Opened #52395. I removed errors property entirely and moved displayName to OptionData type as it is generated for LHN options on client-side

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 13, 2024
@melvin-bot melvin-bot bot changed the title [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ [HOLD for payment 2024-11-20] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Nov 13, 2024

This comment was marked as off-topic.

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 13, 2024

This comment was marked as off-topic.

This comment was marked as outdated.

@puneetlath puneetlath changed the title [HOLD for payment 2024-11-20] [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ [LHN Mismatch] Move client-only keys from report_ to reportMetadata_ Nov 13, 2024
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

4 participants