Page MenuHomePhabricator

[lib] Populate messageStore.threads from threadInfos before setMessageStoreMessages
ClosedPublic

Authored by ashoat on Nov 18 2022, 6:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 23, 6:50 AM
Unknown Object (File)
Mon, Dec 23, 6:50 AM
Unknown Object (File)
Mon, Dec 23, 6:50 AM
Unknown Object (File)
Mon, Dec 23, 6:49 AM
Unknown Object (File)
Mon, Dec 23, 6:47 AM
Unknown Object (File)
Fri, Dec 20, 4:48 AM
Unknown Object (File)
Fri, Dec 6, 8:21 PM
Unknown Object (File)
Wed, Dec 4, 9:09 AM
Subscribers
None

Details

Summary

See ENG-2275, specifically this comment.

We were seeing an exception being thrown because messageStore.threads was missing a thread that was in SQLite. Calling updateMessageStoreWithLatestThreadInfos before this exception might help address the issue by making sure messageStore.threads has an entry for every threadInfo that we have in SQLite.

The exception may still be thrown after this diff, but it would require SQLite's threads table to be inconsistent with its messages table, rather than just redux-persist's messageStore.threads being inconsistent with SQLite's messages table.

Test Plan

Confirm that issue in ENG-2275 no longer repros

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lib/reducers/message-reducer.js
189–193 ↗(On Diff #18567)

These should never have been typed as $ReadOnly. The arrays are constructed anew in the function, so it's okay for the caller to do whatever they want with them

571–575 ↗(On Diff #18567)

Same as above

1364 ↗(On Diff #18567)

I removed this early exit since processMessageStoreOperations is a clean no-op when messageStoreOperations is empty anyways

1381–1384 ↗(On Diff #18567)

This is the same as just returning processedMessageStore directly

Tested this and it works to prevent crash, but the messages are all still lost since when the SAVE_MESSAGES action gets processed it ends up triggering updateMessageStoreWithLatestThreadInfos with an empty ThreadStore and thus generating a remove_messages_for_threads op to delete messages from SQLite. D5667 is still needed to prevent the SAVE_MESSAGES action from firing, but this change is still a good change.

This revision is now accepted and ready to land.Nov 21 2022, 1:38 PM