cache: Eliminate transformed_bulk_cached_fetch.

Its two callers now just directly call
generic_bulk_cached_fetch with the explicit `lambda
obj: obj` helpers.
This commit is contained in:
Steve Howell 2023-07-19 17:14:43 +00:00 committed by Tim Abbott
parent d19c1f7438
commit 3599b1662e
2 changed files with 7 additions and 22 deletions

View File

@ -395,25 +395,6 @@ def generic_bulk_cached_fetch(
}
def transformed_bulk_cached_fetch(
cache_key_function: Callable[[ObjKT], str],
query_function: Callable[[List[ObjKT]], Iterable[ItemT]],
object_ids: Sequence[ObjKT],
*,
id_fetcher: Callable[[ItemT], ObjKT],
cache_transformer: Callable[[ItemT], CacheItemT],
) -> Dict[ObjKT, CacheItemT]:
return generic_bulk_cached_fetch(
cache_key_function,
query_function,
object_ids,
extractor=lambda obj: obj,
setter=lambda obj: obj,
id_fetcher=id_fetcher,
cache_transformer=cache_transformer,
)
def bulk_cached_fetch(
cache_key_function: Callable[[ObjKT], str],
query_function: Callable[[List[ObjKT]], Iterable[ItemT]],
@ -421,11 +402,13 @@ def bulk_cached_fetch(
*,
id_fetcher: Callable[[ItemT], ObjKT],
) -> Dict[ObjKT, ItemT]:
return transformed_bulk_cached_fetch(
return generic_bulk_cached_fetch(
cache_key_function,
query_function,
object_ids,
id_fetcher=id_fetcher,
extractor=lambda obj: obj,
setter=lambda obj: obj,
cache_transformer=lambda obj: obj,
)

View File

@ -6,8 +6,8 @@ from zerver.lib.cache import (
bulk_cached_fetch,
cache_with_key,
display_recipient_cache_key,
generic_bulk_cached_fetch,
single_user_display_recipient_cache_key,
transformed_bulk_cached_fetch,
)
from zerver.lib.types import DisplayRecipientT, UserDisplayRecipient
from zerver.models import Recipient, Stream, UserProfile, bulk_get_huddle_user_ids
@ -103,12 +103,14 @@ def bulk_fetch_stream_names(
return row["name"]
# ItemT = TinyStreamResult, CacheItemT = str (name), ObjKT = int (recipient_id)
stream_display_recipients: Dict[int, str] = transformed_bulk_cached_fetch(
stream_display_recipients: Dict[int, str] = generic_bulk_cached_fetch(
cache_key_function=display_recipient_cache_key,
query_function=get_tiny_stream_rows,
object_ids=recipient_ids,
id_fetcher=get_recipient_id,
cache_transformer=get_name,
setter=lambda obj: obj,
extractor=lambda obj: obj,
)
return stream_display_recipients