Skip to content

Optimize ProjectDataService.getProjectData() #5398

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

Closed
lambourn opened this issue Sep 24, 2020 · 0 comments · Fixed by #5478
Closed

Optimize ProjectDataService.getProjectData() #5398

lambourn opened this issue Sep 24, 2020 · 0 comments · Fixed by #5478
Labels

Comments

@lambourn
Copy link

lambourn commented Sep 24, 2020

Is your feature request related to a problem? Please describe.

While developing a before-prepare hook that should adjust some CI aspects (use different bundle IDs, setup dynamic code signing. etc.) I wanted to modify some content on the injected $projectData object from inside the hook.

However, my changes applied in the hook were all gone after the hook was done. In the end, the CLI worked on the same ProjectData object instance but all modified data was wiped.

I debugged the CLI and found that ProjectDataService.getProjectData() is called ridicously often by the CLI. While that still might ok, the internal caching mechanism itself is just not used at all. This leads to unnecessary re-initialization of the projectData over and over again and the cache has no effect at all.

Relevant code snippet

public getProjectData(projectDir: string): IProjectData {
projectDir = projectDir || this.defaultProjectDir;
this.projectDataCache[projectDir] =
this.projectDataCache[projectDir] ||
this.$injector.resolve<IProjectData>(ProjectData);
this.projectDataCache[projectDir].initializeProjectData(projectDir);
return this.projectDataCache[projectDir];
}

Describe the solution you'd like

The getProjectData is missing a simple check if the project data has been initialized already. If not, initialize it, otherwise return the cached value.

I monkey-patched this locally and it works for me. Not sure of any side-effects, though. It goes like this:

public getProjectData(projectDir: string): IProjectData {
    projectDir = projectDir || this.defaultProjectDir;
    this.projectDataCache[projectDir] =
        this.projectDataCache[projectDir] ||
        this.$injector.resolve<IProjectData>(ProjectData);
    if (!this.projectDataCache[projectDir].initialized) {
        this.projectDataCache[projectDir].initializeProjectData(projectDir);
        // either have initializeProjectData taking care of setting the flag or set it here
        // (or use any of the existing properties that get initialized in initializeProjectData...)
        this.projectDataCache[projectDir].initialized = true;
    }
    return this.projectDataCache[projectDir];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants