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

Request only hash from dev-server #6197

Merged
merged 10 commits into from
Aug 14, 2019
Merged

Request only hash from dev-server #6197

merged 10 commits into from
Aug 14, 2019

Conversation

caalador
Copy link
Contributor

@caalador caalador commented Aug 7, 2019

In dev mode when parsing the stats file for
template sources only request the latest
stats hash from dev-server.

This instead of requesting the whole
stats file for checking the hash before choosing
if the cache should be updated.

Fixes #6191


This change is Reviewable

In dev mode when parsing the stats file for
template sources only request the latest
stats hash from dev-server.

This instead of requesting the whole
stats file for checking the hash before choosing
if the cache should be updated.
@project-bot project-bot bot added this to Review in progress in OLD Vaadin Flow ongoing work (Vaadin 10+) Aug 7, 2019
Getting the hash now also tales into
account production mode and disabled
dev server.
Add missing close for scanner
For production mode and disable dev server
mode only read the stats.json once.
For dev mode read it again if the hash changes.
@ujoni ujoni self-assigned this Aug 13, 2019
Copy link
Contributor

@ujoni ujoni left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, 2 of 2 files at r2.
Reviewable status: 5 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador)


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 33 at r2 (raw file):

import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.function.DeploymentConfiguration;

Unrelated to the actual PR, but why in the world is DeploymentConfiguration in flow.function? 😕


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 175 at r2 (raw file):

                .equals(hash)) {
            // Only load for null jsonStats if we use bundle files.
            if(jsonStats == null || !usesBundleFile(config)) {

The comment and if clause do not match. The comment states that "Only load for null jsonStats if.." but the if clause starts as "Always load for null jsonStats" (since it is followed by or operator). What is the correct approach here?

If we follow the comment, the if would be if (jsonStats != null || usesBundleFile(config))


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 201 at r2 (raw file):

    }

    private void updateCache(String url, String fileContents) {

This method is now in a weird place, since half of its code is duplicated getSourcesFromStats and it is called from one place only, getSourcesFromStats.

Should thing be changed into

  private String getCachedStatsSource(String url) {
     if (jsonStats != null) {
        return cache.computeIfAbsent(url, u -> BundleParser.getSourceFromStatistics(u, jsonStats);
     } else {
        return null;
     }
  }

The only current call to this method would be replaced by setting the jsonStats and getSourcesFromStats would return value from this method. I guess the setting of jsonStats would need to reset the cache.

Idk. Thoughts?


flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java, line 397 at r2 (raw file):

        }

        return "";

Why empty string? Is this some magical effective java trick I have not encountered?

Copy link
Contributor Author

@caalador caalador left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador and @ujoni)


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 33 at r2 (raw file):

Previously, ujoni (Joni) wrote…

Unrelated to the actual PR, but why in the world is DeploymentConfiguration in flow.function? 😕

#2435
No extra memory of it.


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 175 at r2 (raw file):

Previously, ujoni (Joni) wrote…

The comment and if clause do not match. The comment states that "Only load for null jsonStats if.." but the if clause starts as "Always load for null jsonStats" (since it is followed by or operator). What is the correct approach here?

If we follow the comment, the if would be if (jsonStats != null || usesBundleFile(config))

Well the hard part is that we should

  • always load if jsonStats is null.
  • else never load when we have a bundle as it never changes.
  • always load a new stats if the hash has changed, but we do not have a bundle.

flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 201 at r2 (raw file):

Previously, ujoni (Joni) wrote…

This method is now in a weird place, since half of its code is duplicated getSourcesFromStats and it is called from one place only, getSourcesFromStats.

Should thing be changed into

  private String getCachedStatsSource(String url) {
     if (jsonStats != null) {
        return cache.computeIfAbsent(url, u -> BundleParser.getSourceFromStatistics(u, jsonStats);
     } else {
        return null;
     }
  }

The only current call to this method would be replaced by setting the jsonStats and getSourcesFromStats would return value from this method. I guess the setting of jsonStats would need to reset the cache.

Idk. Thoughts?

Update chache is refresh cache eg. clear and parse the new stats. renamed and moved the lock so we lock at the correct position.


flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java, line 397 at r2 (raw file):

Previously, ujoni (Joni) wrote…

Why empty string? Is this some magical effective java trick I have not encountered?

The magic is that we always want to do a stats equals hash check and for production mode we do not care what the hash is as we load the stats once and do not want to load it another time for getting the hash as we know that it doesn't change. as such it's fine to return anything at this point if we are not in dev mode.

fix lock position.
Copy link
Contributor

@ujoni ujoni left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador and @ujoni)


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 175 at r2 (raw file):

Previously, caalador wrote…

Well the hard part is that we should

  • always load if jsonStats is null.
  • else never load when we have a bundle as it never changes.
  • always load a new stats if the hash has changed, but we do not have a bundle.

Alright, the if matches that. Maybe just slap that bullet point as the comment :D


flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java, line 397 at r2 (raw file):

Previously, caalador wrote…

The magic is that we always want to do a stats equals hash check and for production mode we do not care what the hash is as we load the stats once and do not want to load it another time for getting the hash as we know that it doesn't change. as such it's fine to return anything at this point if we are not in dev mode.

Fair enough

Copy link
Contributor Author

@caalador caalador left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador and @ujoni)


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 175 at r2 (raw file):

Previously, ujoni (Joni) wrote…

Alright, the if matches that. Maybe just slap that bullet point as the comment :D

added

Copy link
Contributor

@ujoni ujoni left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3.
Reviewable status: 3 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador and @ujoni)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Review in progress to Reviewer approved Aug 13, 2019
ujoni
ujoni previously approved these changes Aug 13, 2019
Copy link
Contributor

@ujoni ujoni left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 3 unresolved discussions, 1 of 1 LGTMs obtained (waiting on @caalador and @ujoni)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Reviewer approved to Review in progress Aug 14, 2019
Copy link
Contributor Author

@caalador caalador left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 unresolved discussions, 0 of 1 LGTMs obtained, and 1 stale (waiting on @caalador and @ujoni)


flow-server/src/main/java/com/vaadin/flow/component/polymertemplate/NpmTemplateParser.java, line 175 at r2 (raw file):

Previously, caalador wrote…

added

simplified.

Copy link
Contributor

@ujoni ujoni left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r4.
Reviewable status: 2 unresolved discussions, 1 of 1 LGTMs obtained (waiting on @caalador)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Review in progress to Reviewer approved Aug 14, 2019
@caalador caalador merged commit bc66cd3 into master Aug 14, 2019
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Reviewer approved to Done - pending release Aug 14, 2019
@caalador caalador deleted the issues/6191_hash_check branch August 14, 2019 12:07
@caalador caalador added this to the 2.0.8 milestone Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

Reading the stats file in dev mode for the hash is slow
2 participants