Skip to content

Cache condition in helpers.Script - #3797

Merged
balloob merged 2 commits into
home-assistant:devfrom
c-w:dev
Oct 11, 2016
Merged

balloob merged 2 commits into
home-assistant:devfrom
c-w:dev

Conversation

@c-w

@c-w c-w commented Oct 10, 2016

Copy link
Copy Markdown
Contributor

Description:

Implementing this as part of Hacktoberfest. The pull-request adds some caching so that we don't always re-create the conditions in the scripts.

The caching is a simple in-memory, per-instance dictionary.
We use __str__ to format cache keys.

This naive implementation has some disadvantages (e.g., we won't be able to cache two conditions that contain references to distinct-but-equivalent object instances and we don't have any control over the size of the condition cache), but for most simple use-cases the approach should be good enough.

Related issue: fixes #3629

Checklist:

  • Local tests with tox run successfully.
  • Tests have been added to verify that the new code works.

The caching is a simple in-memory, per-instance dictionary.
We use __str__ to format cache keys.

This naive implementation has some disadvantages (e.g., we won't be able
to cache two conditions that contain references to
distinct-but-equivalent object instances and we don't have any control
over the size of the condition cache), but for most simple use-cases the
approach should be good enough.

Resolves #3629
@mention-bot

Copy link
Copy Markdown

@c-w, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabianhjr and @gwendalg to be potential reviewers.

@balloob

balloob commented Oct 11, 2016

Copy link
Copy Markdown
Member

This is awesome! Thanks 👍 👯‍♂️ 🐬

@balloob
balloob merged commit 711526e into home-assistant:dev Oct 11, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
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.

Helpers.Script should cache condition

4 participants