feat(cache): add channel info cache with TTL and throttling
Docker Image CI / build (push) Has been cancelled

Introduce `cached_get_chat` in `tg_cache` to store channel metadata on disk with a configurable TTL (default 12 hours). Use the `tg_rpc` throttling context for RPC calls. Update `rss_generator` to use the cached version and document related environment variables in `dockercompose.yml`.
This commit is contained in:
vvzvlad
2026-06-05 20:45:08 +03:00
parent 021f16cf14
commit 080dae3e74
4 changed files with 165 additions and 4 deletions
+4 -2
View File
@@ -344,7 +344,8 @@ async def generate_channel_rss(channel: str | int,
channel_info_start_time = time.time()
try:
channel = post_parser.channel_name_prepare(channel)
channel_info = await post_parser.client.get_chat(channel)
from tg_cache import cached_get_chat
channel_info = await cached_get_chat(post_parser.client, channel)
channel_title = channel_info.title or f"Telegram: {channel}"
channel_username = channel_info.username or (str(channel_info.id) if channel_info.id and str(channel_info.id).startswith('-100') else None)
if not channel_username:
@@ -556,7 +557,8 @@ async def generate_channel_html(channel: str | int,
try:
channel = post_parser.channel_name_prepare(channel)
logger.debug(f"Prepared channel identifier for HTML: {channel} (type: {type(channel)})") # Log prepared channel
channel_info = await post_parser.client.get_chat(channel)
from tg_cache import cached_get_chat
channel_info = await cached_get_chat(post_parser.client, channel)
channel_username = channel_info.username or (str(channel_info.id) if channel_info.id and str(channel_info.id).startswith('-100') else None)
if not channel_username:
logger.warning(f"Could not get username for channel {channel} in HTML generation, returning error feed structure (as string). NOTE: This should ideally return HTML error page.")