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

(BSR) perf(firebase): gestion des performances par firebase #7271

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pcanthelou-pass
Copy link
Contributor

Link to JIRA ticket: https://passculture.atlassian.net/browse/PC-XXXXX

Flakiness

If I had to re-run tests in the CI due to flakiness, I add the incident on Notion

Checklist

I have:

  • Made sure my feature is working on web.
  • Made sure my feature is working on mobile (depending on relevance : real or virtual devices)
  • Written unit tests native (and web when implementation is different) for my feature.
  • Added a screenshot for UI tickets or deleted the screenshot section if no UI change
  • If my PR is a bugfix, I add the link of the "résolution de problème sur le bug" on Notion
  • I am aware of all the best practices and respected them.

Screenshots

delete if no UI change

Platform Mockup/Before After
iOS
Android
Phone - Chrome
Desktop - Chrome

Best Practices

Click to expand
  • Remove non-null assertion operators (just like other type assertions, this doesn’t change the runtime behavior of your code, so it’s important to only use ! when you know that the value can’t be null or undefined).

Test specific:

  • When you see a local variable that is over-written in every test, mock it.
  • Prefer user to fireEvent.

@pcanthelou-pass pcanthelou-pass changed the title (BSR) perf: gestion des performances par firebase (BSR) perf(firebase): gestion des performances par firebase Nov 24, 2024
Copy link

sonarcloud bot commented Nov 25, 2024

Copy link

sonarcloud bot commented Nov 25, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
80.4% Coverage on New Code (required ≥ 85%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@xlecunff-pass xlecunff-pass left a comment

Choose a reason for hiding this comment

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

Hello, je passe juste par là, stylé que tu ais les mains encore dans le code, je te fait des retours sur les bonnes pratiques au sein de l'équipe plus que sur la partie métier.

  • essaie de remplacer tous les fichiers .tsx qui n'utilisent pas de jsx par des fichiers ts
  • remplace les test('...') par it('should ...')

Comment on lines +30 to +33

jest.mock('shared/performance/useFirebasePerformanceProfiler', () => ({
useFirebasePerformanceProfiler: jest.fn(),
}))
Copy link
Contributor

Choose a reason for hiding this comment

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

Il faudrait mettre ce mock dans les fichiers de tests concernés, dans le cas contraire ce mock sera chargé même dans les fichiers qui ne l'utilisent pas #6531

const { isConnected } = useNetInfoContext()
const { isLoggedIn } = useAuthContext()

useFirebasePerformanceProfiler('Favorites', { route } as UsePerformanceProfilerOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

le as peut-être supprimé

@@ -158,6 +152,8 @@ export const ThematicHome: FunctionComponent = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasGeolocPosition, isFromDeeplink])

useFirebasePerformanceProfiler('ThematicHome', { route } as UsePerformanceProfilerOptions)
Copy link
Contributor

Choose a reason for hiding this comment

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

on peut supprimer le as

Comment on lines +3 to +8
class MyDate extends Date {
constructor(date: string) {
super(date)
}
now = () => 1732384186972
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Bien vu pour l'injection de dépendance, mais on ne l'utilise pas dans le code pour le moment on utilise mockdate.set(date)

On va préférer avoir un objet avec des fonctions comme la majorité de l'équipe n'a pas de connaissance sur l'OOP

Copy link
Contributor

Choose a reason for hiding this comment

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

on peut peut-être utiliser un autre nom de classe que le MyDate


describe('AppStartTimeStore', () => {
test('When start time the start time is correct', () => {
const t = MyDate.now()
Copy link
Contributor

Choose a reason for hiding this comment

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

on peut peut-être utiliser un autre nom de classe que le t

Comment on lines +10 to +14
// Supprimer les espaces en début et fin
let sanitized = name.trim()
// Supprimer les underscores au début et à la fin
sanitized = sanitized.replace(/(^_+)|(_+$)/g, '')
// Tronquer à 32 caractères maximum
Copy link
Contributor

Choose a reason for hiding this comment

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

les commentaires peuvent peut-être supprimés pour un naming plus parlant ou un stringBuilder pour encapsuler les implémentation de méthodes et exposer des noms parlant (overkill)

@@ -0,0 +1,324 @@
/* eslint-disable no-restricted-imports */
Copy link
Contributor

Choose a reason for hiding this comment

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

import { act, renderHook } from 'tests/utils' et renommer en .ts

import { PerformanceService, InteractionService } from './types'
import { usePerformanceProfiler } from './usePerformanceProfiler'

test('Ne fait rien si on ne veut pas profiler', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Peut-être mettre des noms de tests en anglais et wrapper le tout avec un describe

xlecunff-pass
xlecunff-pass previously approved these changes Nov 25, 2024
Comment on lines +28 to +36
type useFirebasePerformanceProfilerProps = {
route?: Route
shouldProfile?: boolean
}

export const useFirebasePerformanceProfiler = (
traceName: string,
props?: useFirebasePerformanceProfilerProps
) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

type useFirebasePerformanceProfilerProps<T extends ScreenNames> = {
  route?: UseRouteType<T>
  shouldProfile?: boolean
}

export const useFirebasePerformanceProfiler = <T extends ScreenNames>(
  traceName: T,
  props?: useFirebasePerformanceProfilerProps<T>
) => {

ce type te permettra d'avoir l'autocomplétion avec toutes les routes et de supprimer le problème avec les as

Copy link
Contributor

Choose a reason for hiding this comment

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

Et bien remplacer le nom du fichier en ts car le tsx à tendance à confondre <T extends ScreenNames> avec des composants

@xlecunff-pass xlecunff-pass dismissed their stale review November 25, 2024 15:32

approved by mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants