Page MenuHomePhabricator

[lib] Avoid unnecessarily mutating MessageStore on processServerRequestsActionType
ClosedPublic

Authored by ashoat on Feb 25 2025, 12:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 5, 1:37 PM
Unknown Object (File)
Sat, Apr 5, 6:29 AM
Unknown Object (File)
Fri, Apr 4, 8:13 PM
Unknown Object (File)
Fri, Apr 4, 7:54 AM
Unknown Object (File)
Wed, Mar 12, 11:39 PM
Unknown Object (File)
Tue, Mar 11, 2:06 AM
Unknown Object (File)
Sun, Mar 9, 4:18 PM
Unknown Object (File)
Sun, Mar 9, 4:10 PM
Subscribers
None

Details

Summary

I noticed that every processServerRequestsActionType was resulting in a new MessageStore. We should avoid mutating the Redux store unless changes are occurring.

Depends on D14401

Test Plan

I used this patch that adds a bunch of logs and ran a Release build of the iOS app pointed at production on my physical iOS device.

The patch includes logs that track when MessageStore changes. I was able to confirm that it's no longer changing as a result of processServerRequestsActionType.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lib/reducers/message-reducer.js
1734 ↗(On Diff #47238)

There's no need to use messageStoreAfterReassignment. The only property of MessageStore that is not enumerated (and as a result, overriden) below is currentAsOf, which is not touched by reassignMessagesToRealizedThreads

tomek added inline comments.
lib/reducers/message-reducer.js
1734 ↗(On Diff #47238)

This change seems risky to me. We're relying on a contract that isn't enforced in any way. I'm afraid that we can forget about it and introduce a hard-to-debug bug in the future.

This revision is now accepted and ready to land.Feb 25 2025, 2:37 AM
lib/reducers/message-reducer.js
1734 ↗(On Diff #47238)

That's a fair concern. I initially wanted to remove messageStore from the return of reassignMessagesToRealizedThreads entirely, but I didn't have time to test changes to updateMessageStoreWithLatestThreadInfos.

However, I'd like to keep this change. Here's my reasoning:

  1. In general, we're moving away from returning updated MessageStore directly, in favor of returning operations.
  2. I don't expect we'll ever need to introduce currentAsOf changes to reassignMessagesToRealizedThreads, as it's simply reassigning thread IDs.
  3. I expect that anybody who would happen to change that would look downstream at all callsites of reassignMessagesToRealizedThreads to make sure their new changes are being picked up appropriately.
  4. They would also need to introduce a new message store op, so they would probably just update the code here to be messageStore: processedMessageStore anyways.
lib/reducers/message-reducer.js
1734 ↗(On Diff #47238)

Makes sense! I was more afraid about introducing a new field to the messageStore, but that would also require reviewing the reducers.