Page MenuHomePhabricator

[native] Update `nextMessagePruneTimeSelector` to use `threadActivityStore`
ClosedPublic

Authored by atul on Oct 12 2023, 8:51 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 19, 10:07 PM
Unknown Object (File)
Sun, Nov 10, 11:02 PM
Unknown Object (File)
Fri, Nov 8, 10:53 AM
Unknown Object (File)
Oct 28 2024, 8:18 PM
Unknown Object (File)
Oct 25 2024, 1:15 AM
Unknown Object (File)
Oct 18 2024, 9:42 PM
Unknown Object (File)
Oct 18 2024, 9:42 PM
Unknown Object (File)
Oct 5 2024, 12:14 AM
Subscribers

Details

Summary

Update nextMessagePruneTimeSelector to use lastNavigatedTo/lastPruned from threadActivityStore instead of messageStore.threads.

IMPORTANT: Labeling as DRAFT because I'm not fully confident in the logic here yet. Putting this up to proceed with ripping out messageStore.threads.[lastNavigatedTo/lastPruned].

Depends on D9454

Test Plan

Change msInHour to small value to trigger pruning and log values. Verify pruning via Redux DevTools.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

atul requested review of this revision.Oct 12 2023, 9:10 AM
atul planned changes to this revision.Oct 12 2023, 9:11 AM
native/selectors/message-selectors.js
26–29 ↗(On Diff #31970)

Hypothetical situation to consider: user is active in many threads but never navigates to any

  1. The first time nextMessagePruneTimeSelector computes nextTime it'll be 21600000 (6 hours from epoch)
  2. User receives 500 messages in eg Comm Supporters, but never navigates to any threads
  3. nextMessagePruneTimeSelector will still compute nextTime as 21600000, because the time hasn't changed MessageStorePruner won't initiate pruning

In this scenario the user would have messages accumulating, but none would be pruned if the user never navigates to a thread.

This is less of a problem an issue with the previous approach because lastPruned gets set to Date.now() as part of newThread. However, the following is still possible:

User is in two threads:

Thread A

  • 5 messages
  • never navigated to
  • never pruned, lastPruned set to hour 6 (when thread added to redux)

Thread B

  • 5 messages
  • never navigated to

never pruned, lastPruned set to hour 12 (when thread added to redux)

At hour 14:

  1. User receives one message in Thread A
  2. nextMessagePruneTimeSelector gets recalculated because state.messageStore.threads changes
  3. threadPruneTime is calculated as hour 18 (Thread B lastPruned + 6 hours)

At hour 100

  1. User receives 500 messages in Thread A
  2. nextMessagePruneTimeSelector gets recalculated because state.messageStore.threads changes
  3. threadPruneTime is calculated as hour 18 (Thread B lastPruned + 6 hours)
  4. threadPruneTime is the same as it was at hour 14, so the useEffect in MessageStorePruner isn't "triggered," and nothing is pruned.

One improvement could be to set lastPruned to Date.now() in reduceThreadActivity for updateThreadLastNavigatedActionType action if lastPruned is unset (eg lastNavigatedTo is being set for the first time).

However, we still have the case (with our lazy loading of threadActivityStore approach) that if a user never navigates to any threads ever, and receives a ton of messages in a never-navigated-to thread: those messages will never be pruned.

If the goal of message pruning is simply to optimize and manage messages as best as possible under "normal conditions," then this is probably adequate. But, if we need a guaranteed method to ensure only a certain number of messages remain in the store for a certain period of time, we might need to consider a different approach.


Personally, I think setting lastPruned to Date.now() in reduceThreadActivity for updateThreadLastNavigatedActionType should be adequate.

If we want to match existing behavior, we could also "eagerly" set lastPruned for all threads in ThreadStore by looking at ThreadDeletionUpdateInfo | ThreadJoinUpdateInfos payloads in reduceThreadActivity.

atul requested review of this revision.Oct 12 2023, 8:38 PM

Undrafting after IRL discussion w/ @ashoat

atul retitled this revision from [DRAFT][native] Update `nextMessagePruneTimeSelector` to use `threadActivityStore` to [native] Update `nextMessagePruneTimeSelector` to use `threadActivityStore`.Oct 12 2023, 8:38 PM

Accepting since my requested change is "obvious" and shouldn't need further review. That said, if you disagree can you re-request review?

native/selectors/message-selectors.js
25 ↗(On Diff #31970)

I don't love that this selector needs to be recomputed every time a new message is added to the MessageStore. After this change it seems to only depend on the list of thread IDs... what do you think of looking at ThreadStore instead?

For context – the only situation where a message can appear in the MessageStore for a thread that isn't in the ThreadStore is a pending message for a pending threads, which should never be pruned.

This revision is now accepted and ready to land.Oct 16 2023, 1:32 PM

address @ashoat's feedback (use threadstore instead of messagestore)

This revision was landed with ongoing or failed builds.Oct 19 2023, 7:45 AM
This revision was automatically updated to reflect the committed changes.