Page MenuHomePhabricator

[lib] only attempt to fetch avatars from auth keyserver once per session
ClosedPublic

Authored by varun on Sep 3 2024, 5:03 PM.
Tags
None
Referenced Files
F3349841: D13235.id43878.diff
Fri, Nov 22, 7:29 PM
F3348735: D13235.diff
Fri, Nov 22, 3:53 PM
Unknown Object (File)
Sun, Nov 10, 2:30 AM
Unknown Object (File)
Sun, Nov 10, 2:30 AM
Unknown Object (File)
Sat, Nov 9, 8:30 PM
Unknown Object (File)
Sat, Nov 9, 4:55 PM
Unknown Object (File)
Oct 18 2024, 11:48 PM
Unknown Object (File)
Oct 18 2024, 9:37 PM
Subscribers

Details

Summary

Resolves https://linear.app/comm/issue/ENG-9065/make-sure-userinfoshandler-doesnt-query-authoritative-keyserver

We want to make sure UserInfosHandler doesn't query for a single user's avatar from the keyserver more than once per app start. We accomplish this by maintaining a set of user IDs for which we've requested avatars

Test Plan

Logged the contents of userIDsWithoutOwnID without this change and saw the same user IDs appearing repeatedly. After this change, user IDs only appeared once in the logs

Diff Detail

Repository
rCOMM Comm
Branch
userinfoshandler
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

varun requested review of this revision.Sep 3 2024, 5:20 PM
ashoat added inline comments.
lib/handlers/user-infos-handler.react.js
98–99

I'd do it in one pass but doesn't really matter

109–112

I've noticed an issue with this sort of caching strategy where an initial timeout can cause the fetch to fail under the user kills & restarts the app

Could be addressed this way:

const updateRelationshipsPromise = (async () => {
  try {
    return await callUpdateRelationships({
      action: relationshipActions.ACKNOWLEDGE,
      userIDs: userIDsWithoutOwnID,
    });
  } catch (e) {
    if (e instanceof FetchTimeout) {
      userIDsWithoutOwnID.forEach(id => requestedAvatarsRef.current.delete(id));
    }
    throw e;
  }
})();
void dispatchActionPromise(
  updateRelationshipsActionTypes,
  updateRelationshipsPromise,
);

(Not sure if it should be FetchTimeout or SocketTimeout – please test to make sure it works.)

This revision is now accepted and ready to land.Sep 3 2024, 6:09 PM
lib/handlers/user-infos-handler.react.js
109–112

It was indeed FetchTimeout. I reduced the timeout for the update_relationships keyserver call to 10ms and was able to reach the if condition in the catch block

Screenshot 2024-09-04 at 10.50.10 AM.png (200×3 px, 230 KB)