Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid requesting the same image more than once [SQSERVICES-1985] #14924

Merged
merged 1 commit into from
Mar 29, 2023

Conversation

atomrc
Copy link
Contributor

@atomrc atomrc commented Mar 28, 2023

BugSQSERVICES-1985 [web] At load time the avatar are downloaded as many times as they are in view

The problem

When the app first loads, when a conversation is displayed there are n avatar requests that are sent at the same time.
Those trigger n actual network request and some of them are targeting the same image.
This ends up in duplicate requests that are hitting backend and eventually putting the webapp in a rate limit state.

The solution

instead of caching the image only when the request is successful, we cache the promise of the request as soon as the request is fired. This way any subsequent request will then get the cached promise and will avoid sending the request on the network

Before

Screenshot 2023-03-28 at 17 40 05

After

Screenshot 2023-03-28 at 17 41 50

@atomrc atomrc marked this pull request as ready for review March 28, 2023 16:21
@atomrc atomrc requested review from a team and otto-the-bot as code owners March 28, 2023 16:21
@atomrc atomrc changed the title fix: Store image loading promise to avoid parallel requests to same image fix: Store image loading promise to avoid parallel requests to same image [SQSERVICES-1985] Mar 28, 2023
@atomrc atomrc changed the title fix: Store image loading promise to avoid parallel requests to same image [SQSERVICES-1985] fix: Avoid requesting the same image more than once [SQSERVICES-1985] Mar 28, 2023
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #14924 (453047b) into dev (0727207) will decrease coverage by 0.01%.
The diff coverage is 30.00%.

@@            Coverage Diff             @@
##              dev   #14924      +/-   ##
==========================================
- Coverage   42.92%   42.91%   -0.01%     
==========================================
  Files         624      624              
  Lines       21320    21322       +2     
  Branches     4899     4899              
==========================================
  Hits         9151     9151              
- Misses      11000    11002       +2     
  Partials     1169     1169              

@atomrc atomrc merged commit 1372ff4 into dev Mar 29, 2023
@atomrc atomrc deleted the fix/image-loading branch March 29, 2023 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants