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
Unknown Object (File)
Thu, Oct 10, 12:33 PM
Unknown Object (File)
Thu, Oct 10, 12:33 PM
Unknown Object (File)
Thu, Oct 10, 12:32 PM
Unknown Object (File)
Thu, Oct 10, 11:47 AM
Unknown Object (File)
Sat, Sep 28, 8:32 PM
Unknown Object (File)
Mon, Sep 23, 7:34 PM
Unknown Object (File)
Mon, Sep 23, 6:41 AM
Unknown Object (File)
Sat, Sep 21, 2:26 AM
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
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #43878)

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

109–112 ↗(On Diff #43878)

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 ↗(On Diff #43878)

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)