-
Notifications
You must be signed in to change notification settings - Fork 7
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
Tech - Correction de la fuite mémoire avec le state vessels
#3742
Conversation
aebd5a4
to
93de412
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done :) Y a plein de comments mais presque tous sont des questions de refacto / goûts.
J'ai vu plein d'import COLORS qui viennent encore de constants, j'ai arrêté les comments liés à ça du coup. Si tu as la motiv tu peux les retirer, sinon c'est pas grave ça sera fait un jour !
['vesselProperties', 'mmsi'], | ||
['vesselProperties', 'ircs'] | ||
], | ||
keys: [['vesselName'], ['internalReferenceNumber'], ['externalReferenceNumber'], ['mmsi'], ['ircs']], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On garde les arrays dans l'array ?
|
||
import type { MainAppThunk } from '@store' | ||
|
||
export const renderVessels = (): MainAppThunk => async (_, getState) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const renderVessels = (): MainAppThunk => async (_, getState) => { | |
export const renderVesselFeatures = (): MainAppThunk => (_, getState) => { |
?
@@ -15,7 +15,7 @@ export const showAlertInSideWindow = | |||
flagState: selectedVessel.flagState, | |||
internalReferenceNumber: selectedVessel.internalReferenceNumber, | |||
ircs: selectedVessel.ircs, | |||
name: selectedVessel?.alerts[0] ?? null | |||
name: selectedVessel?.alerts?.length ? selectedVessel?.alerts[0] : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: selectedVessel?.alerts?.length ? selectedVessel?.alerts[0] : null | |
name: selectedVessel.alerts?.length ? selectedVessel?.alerts[0] : null |
// @ts-ignore | ||
const extent = getExtentFromGeoJSON(zonesSelected[0]?.feature) | ||
if (extent?.length && !isNumeric(extent[0]) && !isNumeric(extent[1])) { | ||
dispatch(setProcessingRegulationSearchedZoneExtent(extent)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je sais que ce n'est pas créé sur cette PR mais le nommer setSelectedRegulationZoneExtent()
ne serait pas plus clair ?
const extent = getExtentFromGeoJSON(zonesSelected[0]?.feature) | ||
if (extent?.length && !isNumeric(extent[0]) && !isNumeric(extent[1])) { | ||
dispatch(setProcessingRegulationSearchedZoneExtent(extent)) | ||
dispatch(animateToExtent()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peut-être en TODO mineure pour plus tard mais je trouve ça plus clair quand une action UI est "auto-contenue". Du genre (en pseudo-code) setExtent(nextExtent: [...], withAnimation: true)
plutôt que de setter d'abord une valeur pour ensuite déclencher l'animation via une autre action qui utilise cette valeur.
const filters = useMainAppSelector(state => state.filter.filters) | ||
const rightMapBoxOpened = useMainAppSelector(state => state.global.rightMapBoxOpened) | ||
|
||
const isOpen = useMemo(() => rightMapBoxOpened === MapBox.FILTERS, [rightMapBoxOpened]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isOpen = useMemo(() => rightMapBoxOpened === MapBox.FILTERS, [rightMapBoxOpened]) | |
const isOpen = rightMapBoxOpened === MapBox.FILTERS |
?
@@ -81,18 +71,18 @@ const VesselAlertLayer = () => { | |||
const { vesselIsHidden, vesselIsOpacityReduced } = getVesselLastPositionVisibilityDates(vesselsLastPositionVisibility) | |||
|
|||
const features = vessels.reduce((features, vessel) => { | |||
if (!vessel.vesselProperties.hasAlert) return features | |||
if (!vessel.hasAlert) return features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un switch(true)
serait plus clean à mon goût mais c'est tout à fait personnel.
+ Même remarque pour les autres layers.
const hideNonSelectedVessels = useSelector(state => state.vessel.hideNonSelectedVessels) | ||
const vesselsTracksShowed = useSelector(state => state.vessel.vesselsTracksShowed) | ||
const selectedVesselIdentity = useSelector(state => state.vessel.selectedVesselIdentity) | ||
const vessels = useSelector(state => vesselSelectors.selectAll(state.vessel.vessels)) | ||
const nonFilteredVesselsAreHidden = useSelector(state => state.filter.nonFilteredVesselsAreHidden) | ||
const previewFilteredVesselsMode = useSelector(state => state.global.previewFilteredVesselsMode) | ||
const hideVesselsAtPort = useSelector(state => state.map.hideVesselsAtPort) | ||
const vesselsLastPositionVisibility = useSelector(state => state.map.vesselsLastPositionVisibility) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hideNonSelectedVessels = useSelector(state => state.vessel.hideNonSelectedVessels) | |
const vesselsTracksShowed = useSelector(state => state.vessel.vesselsTracksShowed) | |
const selectedVesselIdentity = useSelector(state => state.vessel.selectedVesselIdentity) | |
const vessels = useSelector(state => vesselSelectors.selectAll(state.vessel.vessels)) | |
const nonFilteredVesselsAreHidden = useSelector(state => state.filter.nonFilteredVesselsAreHidden) | |
const previewFilteredVesselsMode = useSelector(state => state.global.previewFilteredVesselsMode) | |
const hideVesselsAtPort = useSelector(state => state.map.hideVesselsAtPort) | |
const vesselsLastPositionVisibility = useSelector(state => state.map.vesselsLastPositionVisibility) | |
const { | |
hideNonSelectedVessels, | |
vesselsTracksShowed, | |
// ... | |
} = useMainAppSelector(state => ({ | |
hideNonSelectedVessels: state.vessel.hideNonSelectedVessels, | |
vesselsTracksShowed: state.vessel.vesselsTracksShowed, | |
// ... | |
})) |
+ Même remarque pour les autres layers.
} from '../../../domain/entities/vessel/vessel' | ||
import { useIsSuperUser } from '../../../auth/hooks/useIsSuperUser' | ||
import { monitorfishMap } from '../../map/monitorfishMap' | ||
import { vesselsAdapter, vesselSelectors } from '../slice' | ||
|
||
const VesselAlertLayer = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposition de TODO : j'en ferais plutôt un hook en memoizant simplement les features plutût qu'un composant memoizé sans rendu.
+ Même remarque pour les autres layers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Autre PR please ^^
@@ -228,18 +233,39 @@ export function VesselsLabelsLayer({ mapMovingAndZoomEvent }) { | |||
} | |||
|
|||
const nextFeaturesAndLabels = features.map(feature => { | |||
const { vesselProperties } = feature | |||
const vesselProperties = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne sais pas si c'est utilisé à plus de deux endroits mais je me pose la question d'un petit util selon ^^.
|
Linked issues
Filtres
features/Filter
persistReducerTyped
et non plus en direct avec le localstorageNavires
features/Vessel
createEntityAdapter
pour les dernières positions des navires (vessels
)vessels
: suppression du sous-objetvesselProperties
VesselsLayer
d'OLvesselsAdapter.setMany
pour éviter les fuites mémoiresVESSELS_VECTOR_SOURCE
etVESSELS_VECTOR_LAYER
dans une constante, en dehors d'un composant Reactfeatuer.get
au lieu defeature.getProperties
pour éviter un shallow copy des propriétésListe des navires
VesselList
pour ne pas écoutervessels
dès le démarrage de l'appuseState
locaux dans le slice