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

feat(property-definitions): make propertyDefintionModel lazy #11454

Merged
merged 12 commits into from
Aug 24, 2022

Conversation

mariusandra
Copy link
Collaborator

Problem

#8257

Changes

Converts propertyDefinitionModel to a lazy-fetching operation, that fetches information about properties only when it needs to.

How did you test this code?

WIP, so no tests yet.

@mariusandra mariusandra changed the title Fix prop def loading Make propertyDefintionModel lazy Aug 23, 2022
@mariusandra mariusandra changed the title Make propertyDefintionModel lazy feat(property-definitions): make propertyDefintionModel lazy Aug 24, 2022
@mariusandra mariusandra marked this pull request as ready for review August 24, 2022 09:49
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

Couple of nits but works well locally

Most interesting thing will be to see what performance is like in production for us.


/** Update cached property definition metadata */
export const updatePropertyDefinition = (propertyDefinitions: PropertyDefinition): void => {
propertyDefinitionsModel.findMounted()?.actions.updatePropertyDefinition(propertyDefinitions)
Copy link
Member

Choose a reason for hiding this comment

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

very nitty: this could call propertyDefinitionsModel.findMounted()?.actions.updatePropertyDefinitions([propertyDefinition]) and the reader doesn't have to look for the number of instances of the letter S to understand what is happening

Copy link
Member

Choose a reason for hiding this comment

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

And then we remove actions.updatePropertyDefinition from the model and there's only one way of doing the thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. I removed the singular action from everywhere now, so we must always pass an array.

if (typeof propertyName === 'string' && !(propertyName in propertyDefinitionStorage)) {
window.setTimeout(
() => propertyDefinitionsModel.findMounted()?.actions.loadPropertyDefinitions([propertyName]),
0
Copy link
Member

Choose a reason for hiding this comment

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

Comment says 10ms code says 0. A mistake or arcane JS :)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the comment. This line still gets a 0ms timeout to not e.g. execute when React is rendering. Once the action is called and there's something to fetch, we add a 10ms debounce.

Object.fromEntries(pending.map((key) => [key, PropertyDefinitionState.Loading]))
)
// and fetch them
const { url } = combineUrl('api/projects/@current/property_definitions/', {
Copy link
Member

Choose a reason for hiding this comment

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

should the URL combination be in api.ts instead of building it and calling api.get here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it should. Moved it!

Copy link
Member

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Code looks good. Though testing locally with 100k property definitions + event-property pairs, I haven't noticed much of a speed difference in the taxonomic filter… I can't rule out that this will have an impact on Cloud at the same time.

}

// nothing new to do
if (!mustLoad) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this could just check Object.keys(pendingStateUpdate).length

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense and changed it. I used the bool as a form of premature optimization, as running Object.keys() does make a new array every time. Probably not worth the extra lines.

@mariusandra mariusandra merged commit f431797 into master Aug 24, 2022
@mariusandra mariusandra deleted the fix-prop-def-loading branch August 24, 2022 11:41
@mariusandra
Copy link
Collaborator Author

Thanks all! Feedback addressed (I hope), so merging.

@mariusandra mariusandra mentioned this pull request Aug 24, 2022
91 tasks
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.

3 participants