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)
Tue, Oct 29, 12:48 PM
Unknown Object (File)
Oct 15 2024, 10:36 PM
Unknown Object (File)
Oct 1 2024, 6:08 AM
Unknown Object (File)
Sep 30 2024, 1:20 AM
Unknown Object (File)
Sep 30 2024, 1:20 AM
Unknown Object (File)
Sep 30 2024, 1:20 AM
Unknown Object (File)
Sep 30 2024, 1:19 AM
Unknown Object (File)
Sep 30 2024, 1:17 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
No Lint Coverage
Unit
No Test Coverage

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