Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Dedupe requests to fetch group profile data #1666

Merged
merged 3 commits into from
Jan 2, 2018

Conversation

lukebarnard1
Copy link
Contributor

@lukebarnard1 lukebarnard1 commented Dec 15, 2017

setTimeout(() => {
delete this._groupProfiles[groupId];
delete this._groupProfilesPromise[groupId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this have to happen in the callback? can't it happen as soon as the promise returns?

Copy link
Contributor Author

@lukebarnard1 lukebarnard1 Dec 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would think that - I did. Empirically that didn't work because it means that a promise could be deleted whilst something is still awaiting it. It's a race because in one version of the resolution, the promise would be deleted.

In this new version I think I've inadvertently created a weird barrier where every resolution sets this._groupProfiles[groupId] and sets its own timeout. Maybe it shouldn't do that.....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why it's a problem if this._groupProfilesPromise is cleared while something is waiting for the promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually my last comment doesn't make sense because the await already has a reference to the promise, it doesn't matter if a reference to the same promise is remove from this._groupProfilesPromise.

this._groupProfilesPromise[groupId] = matrixClient.getGroupProfile(groupId);
}

const profile = await this._groupProfilesPromise[groupId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to think about what happens if the getGroupProfile request fails. I think you'll get stuck with a failed promise, which is sad-making.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the error will be thrown as normal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but then every attempt to get the profile for this group will then fail immediately for the next half-hour, even if whatever network blip made the first request fail is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, I shall wrap it with a try/catch and delete the failed promise in the catch.

Also, delete the groupProfilePromise immediately after setting
the group profile (the first if-statement will prevent a new
request from being started).
@lukebarnard1 lukebarnard1 force-pushed the luke/fix-duplicate-group-profile-requests branch from 0e2c1b6 to 3947a72 Compare January 2, 2018 10:44
@lukebarnard1
Copy link
Contributor Author

lukebarnard1 commented Jan 2, 2018

Travis seems to be failing due to nvm not being able to download the Node.js binary, and then deciding to build it from source. "Yey". (https://travis-ci.org/matrix-org/matrix-react-sdk/builds/324079818?utm_source=github_status&utm_medium=notification)

@lukebarnard1
Copy link
Contributor Author

Having restarted the build, it seems to have been made happy.

try {
profile = await this._groupProfilesPromise[groupId];
} catch (e) {
// Don't retry, but allow a retry when the profile is next requested
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we perhaps want to log the exception here, just in case it's something unexpectedly bad?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, seems fair

@ara4n
Copy link
Member

ara4n commented Jan 2, 2018

lgtm mod comment

@ara4n ara4n assigned lukebarnard1 and unassigned richvdh Jan 2, 2018
@lukebarnard1 lukebarnard1 merged commit 5abf044 into develop Jan 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dedupe group profile requests
3 participants