Skip to content

[logbook] implement shouldUpdate#4832

Merged
balloob merged 2 commits into
home-assistant:devfrom
KapJI:logbook-should-update
Feb 11, 2020
Merged

[logbook] implement shouldUpdate#4832
balloob merged 2 commits into
home-assistant:devfrom
KapJI:logbook-should-update

Conversation

@KapJI
Copy link
Copy Markdown
Member

@KapJI KapJI commented Feb 10, 2020

Proposed change

I noticed many unnecessary calls of loogbook render. This is because of updated hass property which actually usually contains no changes. This is especially bad when there are many entries loaded and causes UI freezes.

Implement shouldUpdate to update logbook only when entries are updated or when rtl is changed.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue:
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Comment thread src/panels/logbook/ha-logbook.ts Outdated
if (changedProps.has("hass")) {
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
if (oldHass && oldHass.language !== this.hass.language) {
this._rtl = computeRTL(this.hass);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We shouldn't have side effects in our shouldUpdate. Setting this._rtl should stay in updated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't evne use this._rtl it seems? We can drop it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is used, reflected attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldUpdate should return true when the language is changed or when entries is changed.

This change will affect state icons btw, they will no longer be updated when a state changed. But I don't think that is a big problem as the icon would not match the logbook entry anyway? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, rtl is used for date title. My idea was calculate this._rtl before the update, so I think performUpdate is a better place than updated.

Copy link
Copy Markdown
Member

@bramkragten bramkragten Feb 11, 2020

Choose a reason for hiding this comment

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

No need to do it in performUpdate as your shouldUpdate is false when _rtl is changed, it will not cause another render.

@KapJI KapJI force-pushed the logbook-should-update branch 2 times, most recently from 315bc95 to db441c1 Compare February 11, 2020 08:57
Comment thread src/panels/logbook/ha-logbook.ts Outdated

protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
protected performUpdate() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

performUpdate is async

Comment thread src/panels/logbook/ha-logbook.ts
@KapJI KapJI force-pushed the logbook-should-update branch from db441c1 to 5a1384f Compare February 11, 2020 12:14
@KapJI
Copy link
Copy Markdown
Member Author

KapJI commented Feb 11, 2020

What I want to achieve here is to make the first render to be executed with correct _rtl value. So just compute it the first thing in the render itself.

Comment thread src/panels/logbook/ha-logbook.ts
@KapJI KapJI force-pushed the logbook-should-update branch from 5a1384f to a0d4472 Compare February 11, 2020 17:34
@KapJI
Copy link
Copy Markdown
Member Author

KapJI commented Feb 11, 2020

Move to updated.

Comment thread src/panels/logbook/ha-logbook.ts Outdated
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
@balloob balloob merged commit d48a4e0 into home-assistant:dev Feb 11, 2020
@bramkragten bramkragten mentioned this pull request Feb 12, 2020
@lock lock Bot locked and limited conversation to collaborators Feb 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants