Skip to content

feat: cache construction of records used to answer queries from the service registry#1243

Merged
bdraco merged 11 commits into
masterfrom
record_caching
Sep 2, 2023
Merged

feat: cache construction of records used to answer queries from the service registry#1243
bdraco merged 11 commits into
masterfrom
record_caching

Conversation

@bdraco

@bdraco bdraco commented Aug 30, 2023

Copy link
Copy Markdown
Member
  • Anything we save for a query response does not need a created time since we only use this for records we are not authoritative for. These records are good until they unregistered.
  • The query_handler was constructing records for every question, when they never change once registered in the registry

Someone could be mutating the data after they register the ServiceInfo but that would be wrong anyways since they should be calling async_update_service with new ServiceInfo since any changes wouldn't be broadcast anyways.

This also has the risk of someone using the ServiceInfo.dns_* calls in tests to mock data, but created= should be easy enough to remove for these cases.

This is not as clean as I would have liked it to be as we have to maintain backwards compat for override_ttl

@codecov

codecov Bot commented Aug 30, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage is 100.00% of modified lines.

Files Changed Coverage
src/zeroconf/__init__.py 100.00%
src/zeroconf/_core.py 100.00%
src/zeroconf/_handlers/query_handler.py 100.00%
src/zeroconf/_services/info.py 100.00%

📢 Thoughts on this report? Let us know!.

Comment thread src/zeroconf/_services/info.py
@bdraco bdraco changed the title fix: cleanup query responses feat: cache construction of records used to answer queries Sep 2, 2023
Comment on lines +187 to +190
self._dns_address_cache: Optional[List[DNSAddress]] = None
self._dns_pointer_cache: Optional[DNSPointer] = None
self._dns_service_cache: Optional[DNSService] = None
self._dns_text_cache: Optional[DNSText] = None

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.

Ideally we would have required a subclass of ServiceInfo to be registered with the registry but thats a design choice we would have needed to make many years ago and would be a breaking change now

@bdraco bdraco marked this pull request as ready for review September 2, 2023 20:26
@bdraco bdraco changed the title feat: cache construction of records used to answer queries feat: cache construction of records used to answer queries from the service registry Sep 2, 2023
@bdraco bdraco merged commit 0890f62 into master Sep 2, 2023
@bdraco bdraco deleted the record_caching branch September 2, 2023 20:27
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.

1 participant