Skip to content

Conversation

@henchaves
Copy link
Member

@henchaves henchaves commented Jul 26, 2023

Description

This PR aims to fix a bug which request many times to the backend to /license and /settings endpoint.

Related Issue

GSK-1087 (available on Linear)

Type of Change

  • 📚 Examples / docs / tutorials / dependencies update
  • 🔧 Bug fix (non-breaking change which fixes an issue)
  • 🥂 Improvement (non-breaking change which improves an existing feature)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🔐 Security fix

@henchaves henchaves self-assigned this Jul 26, 2023
@linear
Copy link

linear bot commented Jul 26, 2023

@henchaves henchaves marked this pull request as ready for review July 26, 2023 22:25
@henchaves henchaves requested a review from kevinmessiaen August 1, 2023 16:06
Copy link
Member

@kevinmessiaen kevinmessiaen left a comment

Choose a reason for hiding this comment

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

Looks good to me! Some small code refactoring possible but it's not directly related to the PR

Comment on lines 67 to 72
let token = this.token;
if (!token) {
const localToken = getLocalToken();
if (localToken) {
this.token = localToken;
token = localToken;
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 think that we really need a token variable since it's always equals to this.token

It seems (need to verify) that we can simplify everything by just

this.token = this.token || getLocalToken()

Copy link
Member Author

@henchaves henchaves Aug 2, 2023

Choose a reason for hiding this comment

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

this doesn't work because getLocalToken() may output null.
that's why there is a double check. let me try to find a better solution to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Could you recheck it?

Copy link
Member

Choose a reason for hiding this comment

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

In that case something like this should work: this.token = this.token || getLocalToken() || ''

Comment on lines 86 to 90
const response = await api.getUserAndAppSettings();
this.isLoggedIn = true;
this.userProfile = response.user;
let appConfig = response.app;
mainStore.setAppSettings(appConfig);
Copy link
Member

@kevinmessiaen kevinmessiaen Aug 2, 2023

Choose a reason for hiding this comment

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

This lines are duplicated with lines 76-80. I think the order of if/else it can be improved to make it more concise

if (!this.isLoggedIn) {
  if (mainStore.authAvailable) {
    this.token = this.token || getLocalToken();
    if (!this.token) {
      this.removeLogin();
      return;
    }
  }
  const response = await api.getUserAndAppSettings();
  this.isLoggedIn = true;
  this.userProfile = response.user;
  mainStore.setAppSettings(response.app);
}

(ideally we should break down to sub function to avoid having too much layers of if)

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 refactored this checkLoggedIn method.
Could you recheck it?

Copy link
Member

@kevinmessiaen kevinmessiaen Aug 3, 2023

Choose a reason for hiding this comment

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

I saw that you forgot about setting this.token, I fixed that so all good to me

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!!

@henchaves henchaves requested a review from kevinmessiaen August 2, 2023 16:02
@kevinmessiaen kevinmessiaen merged commit 70cea61 into main Aug 3, 2023
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Hartorn Hartorn deleted the feature/gsk-1087-a-lot-of-subsequent-settingslicense-requests branch September 13, 2023 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants