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

Onyx Connection Manager #567

Merged
merged 36 commits into from
Aug 22, 2024

Conversation

fabioh8010
Copy link
Contributor

@fabioh8010 fabioh8010 commented Jul 8, 2024

Details

This PR implements a general connection manager to handle all Onyx connections. Key features:

  • Connection reuse: Connections made to the same Onyx key with the same configurations are reused instead of being kept separately, thus reducing JS processing and overhead when the Onyx key's data changes and needs to broadcast to the connections. This approach can significantly reduce the total number of connections during the application's runtime and it's supported by both Onyx.connect() and useOnyx() subscribers. Since withOnyx() subscribers connects to Onyx keys in a different way than the first ones, they can't be reused and will work the same way as before.
  • Centralized logic: Both Onyx.connect(), useOnyx() and withOnyx() subscribes will use the connection manager to handle their connections, keeping the logic centralized and allowing easier maintenance and future improvements.

Slack thread: https://expensify.slack.com/archives/C05LX9D6E07/p1723058474781739

E/App PR: Expensify/App#44987

Related Issues

Expensify/App#47143

Automated Tests

  • Tests related to Onyx Connection Manager.
  • Additional tests to useOnyx.
  • Adjusting other tests.

Manual Tests

Common actions in the App, e.g.:

  1. Open a chat.
  2. Send a message, react to that message.
  3. Reply to that message as a thread.
  4. Submit an expense, open that expense.
  5. Assign a task, open that task and mark it as complete.
  6. Go to Settings and change the App theme.

Author Checklist

  • I linked the correct issue in the ### Related Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Screen.Recording.2024-08-07.at.18.00.00-compressed.mov
Android: mWeb Chrome
Screen.Recording.2024-08-07.at.18.03.55-compressed.mov
iOS: Native
Screen.Recording.2024-08-07.at.18.26.23-compressed.mov
iOS: mWeb Safari
Screen.Recording.2024-08-07.at.18.39.19-compressed.mov
MacOS: Chrome / Safari
Screen.Recording.2024-08-07.at.18.41.08-compressed.mov
Screen.Recording.2024-08-07.at.18.43.55-compressed.mov
MacOS: Desktop
Screen.Recording.2024-08-07.at.18.52.43-compressed.mov

@fabioh8010 fabioh8010 requested a review from a team as a code owner August 14, 2024 15:41
@melvin-bot melvin-bot bot requested review from srikarparsi and removed request for a team August 14, 2024 15:41
@mountiny
Copy link
Contributor

@fabioh8010 can you apply the changes from here to the App PR Expensify/App#44987 (or create a separate draft for testing) so we can create a build and ask QA for testing before merging this?

@mountiny
Copy link
Contributor

Asked for a C+ volunteer

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Havent done a full review yet, but excited for this change

tests/unit/onyxCacheTest.tsx Show resolved Hide resolved
lib/OnyxUtils.ts Show resolved Hide resolved
lib/OnyxUtils.ts Show resolved Hide resolved
lib/OnyxUtils.ts Outdated Show resolved Hide resolved
lib/OnyxUtils.ts Outdated Show resolved Hide resolved
lib/OnyxConnectionManager.ts Outdated Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
Copy link
Contributor

@chrispader chrispader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really love this PR. Awesome work @fabioh8010 ! 👏

I just have a few questions, but the code seems very logical and well designed.

lib/OnyxUtils.ts Show resolved Hide resolved
lib/OnyxUtils.ts Outdated Show resolved Hide resolved
API.md Show resolved Hide resolved
lib/OnyxUtils.ts Outdated Show resolved Hide resolved
lib/types.ts Outdated Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
lib/OnyxUtils.ts Outdated Show resolved Hide resolved
lib/OnyxConnectionManager.ts Show resolved Hide resolved
Copy link
Contributor

@chrispader chrispader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

Copy link
Contributor

@blazejkustra blazejkustra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement @fabioh8010! 🚀

@tgolen
Copy link
Collaborator

tgolen commented Aug 21, 2024

Now that this is approved, let's talk about rolling this out. Any thoughts on how to do it safely?

Normally, I would say that QA should do a full regression test on an ad-hoc build of E/App. However, they currently have 4-5 ad-hoc builds they are doing regression tests on, so it could be a while before they get to this.

I'm sort of thinking that the nature of this PR means that either everything works as normal, or everything will be massively broken 😂 So, maybe we can get away with:

  • HOLD this PR so it is not merged yet
  • Create an E/App PR that points package.json to the commit of this branch
  • Test it out and verify there are no issues with most of our core flows (maybe have a C+ or two do some testing)
  • Once the E/App PR is tested and any bugs are fixed, merge this PR
  • Update the E/App PR to point package.json to the newly released version

@fabioh8010
Copy link
Contributor Author

Hi @tgolen , I already have the E/App PR here pointing to a release I made with these changes in my repo.

The C+ assigned tested and didn't found any bugs so far.

I think the best approach would be having the full regression test with ad-hoc build, even if we have to wait a little bit. In this way we would ensure more safety before these changes are merged. WDYT?

@tgolen
Copy link
Collaborator

tgolen commented Aug 21, 2024

Ah, nice. You were well ahead of me!

I discussed with @mountiny @roryabraham @luacmartins and @AndrewGable and we all agreed that this doesn't need ad-hoc testing. That's mostly based on the idea that fundamentally, this PR will either work fine, or break everything. It is also a simple change to revert (for E/App at least). Because of that, we're fine with it just going to staging like normal.

Is that OK?

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @tgolen We could try this out in main and staging given @ikevin127 did not find any problems so far

@fabioh8010
Copy link
Contributor Author

Yeah I think it makes sense, let's :shipit: then

@tgolen tgolen merged commit b0c35b2 into Expensify:main Aug 22, 2024
5 checks passed
Copy link
Contributor

🚀Published to npm in v2.0.65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants