Switch hassio to use iter_chunks (#102031)

This commit is contained in:
J. Nick Koston 2023-10-15 09:48:04 -10:00 committed by GitHub
parent 471d1abe47
commit 683046272d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -178,7 +178,10 @@ class HassIOView(HomeAssistantView):
if should_compress(response.content_type): if should_compress(response.content_type):
response.enable_compression() response.enable_compression()
await response.prepare(request) await response.prepare(request)
async for data in client.content.iter_chunked(8192): # In testing iter_chunked, iter_any, and iter_chunks:
# iter_chunks was the best performing option since
# it does not have to do as much re-assembly
async for data, _ in client.content.iter_chunks():
await response.write(data) await response.write(data)
return response return response

View File

@ -198,7 +198,10 @@ class HassIOIngress(HomeAssistantView):
if should_compress(response.content_type): if should_compress(response.content_type):
response.enable_compression() response.enable_compression()
await response.prepare(request) await response.prepare(request)
async for data in result.content.iter_chunked(8192): # In testing iter_chunked, iter_any, and iter_chunks:
# iter_chunks was the best performing option since
# it does not have to do as much re-assembly
async for data, _ in result.content.iter_chunks():
await response.write(data) await response.write(data)
except ( except (