Page MenuHomePhabricator

[web][native] Extract the common logic determining when to clear the data
ClosedPublic

Authored by tomek on Apr 3 2024, 4:57 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Dec 22, 2:32 AM
Unknown Object (File)
Sun, Dec 22, 2:32 AM
Unknown Object (File)
Sun, Dec 22, 2:32 AM
Unknown Object (File)
Sun, Dec 22, 2:32 AM
Unknown Object (File)
Sun, Dec 22, 2:32 AM
Unknown Object (File)
Tue, Dec 17, 1:07 AM
Unknown Object (File)
Sat, Dec 14, 7:48 AM
Unknown Object (File)
Wed, Nov 27, 3:52 PM
Subscribers

Details

Summary

If the ID of the current user changes and was defined we should clear both Redux and SQLite.

https://linear.app/comm/issue/ENG-7076/extract-common-logic-from-sqlite-handler-and-master-reducer

Depends on D11533

Test Plan

Check if logging out clears both Redux and SQLite.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tomek requested review of this revision.Apr 3 2024, 5:12 AM
native/redux/redux-setup.js
273 ↗(On Diff #38721)

Is this still necessary? Anonymous user info, and null user info, will both fail !!oldUserID check

web/shared-worker/sqlite-data-handler.js
57 ↗(On Diff #38721)

why isn't this shouldClearData(currentLoggedInUserID, currentDBUserID)?
why was this change made? before if currentLoggedInUserID && currentLoggedInUserID === currentDBUserID && errorGettingUserID this code would also run

web/redux/redux-setup.js
344–345 ↗(On Diff #38721)

It looks like in the past, resetUserSpecificState would execute when going from a logged-out state (no currentUserInfo) to a logged-in state (non-anonymous currentUserInfo). After your changes, this no longer happens. Was this change intentional? Is it consistent with behavior on the SQLite side?

native/redux/redux-setup.js
273 ↗(On Diff #38721)

Yeah, it isn't. Going to remove it.

web/redux/redux-setup.js
344–345 ↗(On Diff #38721)

Yes, it is intentional. The idea behind resetting the state is to protect the user's data. If a user was logged in and becomes logged out or a new user becomes logged in - we should clear the data. But if a user wasn't logged in and becomes logged in, we can assume that they were able to access the data from the store - so there's no point in clearing it.

On the SQLite side, we're doing something similar - if in the DB userID is null we don't clear the DB. The consistency is enforced by using shouldClearData in both places.

web/shared-worker/sqlite-data-handler.js
57 ↗(On Diff #38721)

why isn't this shouldClearData(currentLoggedInUserID, currentDBUserID)?

The logic is indeed the same, but it is a coincidence. We can decide to modify shouldClearData function without updating this place. In this place, we're simply making sure that the owner of the DB is correctly updated.

why was this change made?

Now it is clear what's the purpose of this code. The intention wasn't to directly replicate the previous behavior, but instead create something obviously correct. Both versions try to achieve the same thing - making sure that the userID in the DB is updated when necessary.

before if currentLoggedInUserID && currentLoggedInUserID === currentDBUserID && errorGettingUserID this code would also run

When currentLoggedInUserID === currentDBUserID then this code is a no-op, and we don't have to run it.

web/redux/redux-setup.js
344–345 ↗(On Diff #38721)

Makes sense, thanks for explaining

Please remove the unnecessary code in all places before landing. Other than that looks good

web/shared-worker/sqlite-data-handler.js
57 ↗(On Diff #38721)

I see, thank you

This revision is now accepted and ready to land.Apr 9 2024, 2:30 AM
tomek marked 5 inline comments as done.

Delete unnecessary conditions

web/shared-worker/sqlite-data-handler.js
57 ↗(On Diff #38721)

Should we have made the same change to SQLiteDataHandler on native? Now it appears that the logic is inconsistent

web/shared-worker/sqlite-data-handler.js
57 ↗(On Diff #38721)

We can follow up in D11670 actually