From 91a0abb6c7a24c0d9ca42b97ec5b6f8e848d6355 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Thu, 19 Feb 2026 17:06:50 -0800 Subject: [PATCH] add batch_load_config for batching LiteLLM_Config queries --- litellm/proxy/db/litellm_config_cache.py | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 litellm/proxy/db/litellm_config_cache.py diff --git a/litellm/proxy/db/litellm_config_cache.py b/litellm/proxy/db/litellm_config_cache.py new file mode 100644 index 00000000000..a559ab9e55d --- /dev/null +++ b/litellm/proxy/db/litellm_config_cache.py @@ -0,0 +1,41 @@ +""" +Batch loader for LiteLLM_Config DB records. + +Replaces multiple find_first/find_unique calls with a single find_many query +during the add_deployment polling cycle. This cuts ~5 DB round-trips per +worker per cycle down to 1. +""" + +from typing import TYPE_CHECKING, Any, Dict, List + +from litellm._logging import verbose_proxy_logger + +if TYPE_CHECKING: + from litellm.proxy.utils import PrismaClient + + +# All param_names queried during the add_deployment polling cycle +POLLING_PARAM_NAMES: List[str] = [ + "general_settings", + "litellm_settings", + "model_cost_map_reload_config", + "anthropic_beta_headers_reload_config", +] + + +async def batch_load_config( + prisma_client: "PrismaClient", +) -> Dict[str, Any]: + """ + Load all polling-relevant LiteLLM_Config records in one query. + + Returns a dict keyed by param_name -> record. + """ + records = await prisma_client.db.litellm_config.find_many( + where={"param_name": {"in": POLLING_PARAM_NAMES}} + ) + config_map: Dict[str, Any] = {record.param_name: record for record in records} + verbose_proxy_logger.debug( + "batch_load_config: loaded %d config records in 1 query", len(config_map) + ) + return config_map