|
3 | 3 | from collections.abc import Iterable, Mapping, MutableMapping
|
4 | 4 | from dataclasses import dataclass, field, replace
|
5 | 5 | from enum import Enum
|
6 |
| -from functools import lru_cache |
| 6 | +from functools import cached_property, lru_cache |
7 | 7 | from operator import itemgetter
|
8 | 8 | from typing import TYPE_CHECKING, Any, NamedTuple
|
9 | 9 |
|
@@ -329,6 +329,10 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
|
329 | 329 | _, configuration_parsed = parse_named_configuration(data, "sharding_indexed")
|
330 | 330 | return cls(**configuration_parsed) # type: ignore[arg-type]
|
331 | 331 |
|
| 332 | + @cached_property |
| 333 | + def codec_pipeline(self) -> BatchedCodecPipeline: |
| 334 | + return BatchedCodecPipeline.from_list(self.codecs) |
| 335 | + |
332 | 336 | def to_dict(self) -> dict[str, JSON]:
|
333 | 337 | return {
|
334 | 338 | "name": "sharding_indexed",
|
@@ -393,7 +397,7 @@ async def _decode_single(
|
393 | 397 | return out
|
394 | 398 |
|
395 | 399 | # decoding chunks and writing them into the output buffer
|
396 |
| - await BatchedCodecPipeline.from_list(self.codecs).read( |
| 400 | + await self.codec_pipeline.read( |
397 | 401 | [
|
398 | 402 | (
|
399 | 403 | _ShardingByteGetter(shard_dict, chunk_coords),
|
@@ -461,7 +465,7 @@ async def _decode_partial_single(
|
461 | 465 | shard_dict[chunk_coords] = chunk_bytes
|
462 | 466 |
|
463 | 467 | # decoding chunks and writing them into the output buffer
|
464 |
| - await BatchedCodecPipeline.from_list(self.codecs).read( |
| 468 | + await self.codec_pipeline.read( |
465 | 469 | [
|
466 | 470 | (
|
467 | 471 | _ShardingByteGetter(shard_dict, chunk_coords),
|
@@ -495,7 +499,7 @@ async def _encode_single(
|
495 | 499 |
|
496 | 500 | shard_builder = _ShardBuilder.create_empty(chunks_per_shard)
|
497 | 501 |
|
498 |
| - await BatchedCodecPipeline.from_list(self.codecs).write( |
| 502 | + await self.codec_pipeline.write( |
499 | 503 | [
|
500 | 504 | (
|
501 | 505 | _ShardingByteSetter(shard_builder, chunk_coords),
|
@@ -538,7 +542,7 @@ async def _encode_partial_single(
|
538 | 542 | )
|
539 | 543 | )
|
540 | 544 |
|
541 |
| - await BatchedCodecPipeline.from_list(self.codecs).write( |
| 545 | + await self.codec_pipeline.write( |
542 | 546 | [
|
543 | 547 | (
|
544 | 548 | _ShardingByteSetter(shard_dict, chunk_coords),
|
|
0 commit comments