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

⚡️ decrease time-to-interactive #162

Merged
merged 8 commits into from
Nov 5, 2020
Merged

Conversation

jsulpis
Copy link
Member

@jsulpis jsulpis commented Oct 13, 2020

Related to #41

I made quite a few changes, I hope it is not too much for one PR. But the logging time (at least perceived) is much shorter.

Here is what I did:

  • remove the call to the auth0 API authenticationClient.getProfile() in the exchangeToken function, which was not necessary since all we got from it was the user email, which we already have from the auth0 authentication. The call to this function was one of the longest so I think we can save several seconds on the production app just by removing it.
  • change the order of some operations: use optimistic UI to display the main content right after the auth0 authentication, and display the rest after the Firebase authentication. Also fetch the list of agencies at the very end since it is in the second page so we don't need it straight away.
  • display a little loader during the Firebase authentication when the main content is already there, to let the user know that there is still something happening in the background so they are not frustrated if an error message shows up (like campaign closed)

@hgwood
Copy link
Member

hgwood commented Oct 14, 2020

Wow! Sounds awesome. I'll try to review and test it this week.

@hgwood hgwood requested review from Ked57 and hgwood October 14, 2020 10:49
Copy link

@EmrysMyrddin EmrysMyrddin left a comment

Choose a reason for hiding this comment

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

LGTM

ui/src/index.ts Outdated
</h2>`;
</div>`;

const statsLoader = `<h2>${htmlLoader} Hold on, we're retrieving the data you requested ...</h2>`;

Choose a reason for hiding this comment

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

For accessibility, can we use something else than a h2 to display information that is not really a title ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put a div instead

@hgwood
Copy link
Member

hgwood commented Oct 14, 2020

I'm getting an error when running the app locally, I'm investigating.

image

Copy link
Member

@hgwood hgwood left a comment

Choose a reason for hiding this comment

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

I'm afraid removing the call to Auth0 is not that easy. Your proposal is not secured. Anyone can call exchangeToken with any values for userId, userEmail, accessToken and get authenticated to Firebase. In the master version, the value for accessToken is validated against Auth0, which ensures that the token is legitimate and that the user really did authenticate to Auth0. This is why Auth0 is called, not just to get the email address. 🙂

@jsulpis jsulpis force-pushed the refactor/improve-logging-time branch from f132f23 to ae2ff6c Compare October 14, 2020 17:03
@jsulpis jsulpis force-pushed the refactor/improve-logging-time branch from ae2ff6c to 993f156 Compare October 14, 2020 17:42
@jsulpis
Copy link
Member Author

jsulpis commented Oct 14, 2020

I'm afraid removing the call to Auth0 is not that easy. Your proposal is not secured. Anyone can call exchangeToken with any values for userId, userEmail, accessToken and get authenticated to Firebase. In the master version, the value for accessToken is validated against Auth0, which ensures that the token is legitimate and that the user really did authenticate to Auth0. This is why Auth0 is called, not just to get the email address. 🙂

Indeed I forgot it was in an API function and thus not redundant with the authentication. I dropped the commit.

Hopefully with the optimistic UI it should still feel faster, but the total logging time will remain roughly the same (very long). So I am not sure if this PR can still close the associated issue ? It strange that some API calls take much more time on the production app than locally, but I won't be able to further analyse this issue.

@hgwood
Copy link
Member

hgwood commented Oct 16, 2020

I'll come back to this PR next week :)

@hgwood
Copy link
Member

hgwood commented Oct 16, 2020

I might have solution for the Auth0 call, see #41 (comment), but let's keep that for another PR.

@hgwood hgwood self-assigned this Nov 3, 2020
@hgwood
Copy link
Member

hgwood commented Nov 5, 2020

Finally got around to test this. It works nicely, thank you. I think it can be improved further. In the current form, the Stats button in the navbar is unresponsive while authenticating to Firebase. I don't think this has to happen. I'm gonna to test a few adjustment to see what I can do.

@hgwood
Copy link
Member

hgwood commented Nov 5, 2020

OK, found something that works a bit better IMO, since it's now possible to navigate to the stats page immediately.

@hgwood hgwood merged commit 9e63489 into master Nov 5, 2020
@hgwood hgwood deleted the refactor/improve-logging-time branch November 5, 2020 14:49
@hgwood hgwood changed the title ⚡️ Improve logging time ⚡️ decrease time-to-interactive Nov 5, 2020
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.

3 participants