diff --git a/discord_rss_bot/custom_filters.py b/discord_rss_bot/custom_filters.py index 8a91fac..069a60a 100644 --- a/discord_rss_bot/custom_filters.py +++ b/discord_rss_bot/custom_filters.py @@ -1,4 +1,5 @@ import urllib.parse +from functools import lru_cache import html2text from loguru import logger @@ -12,6 +13,7 @@ from discord_rss_bot.settings import get_reader reader: Reader = get_reader() +@lru_cache() def encode_url(url_to_quote: str) -> str: """%-escape the URL so it can be used in a URL. @@ -61,6 +63,7 @@ def entry_is_blacklisted(entry_to_check: Entry) -> bool: return bool(has_black_tags(reader, entry_to_check.feed) and should_be_skipped(reader, entry_to_check)) +@lru_cache() def convert_to_md(thing: str) -> str: """Discord does not support tables so we need to remove them from the markdown.""" logger.debug(f"Converting {thing} to markdown.") diff --git a/discord_rss_bot/custom_message.py b/discord_rss_bot/custom_message.py index 20c00b8..c3294b4 100644 --- a/discord_rss_bot/custom_message.py +++ b/discord_rss_bot/custom_message.py @@ -1,4 +1,5 @@ import re +from functools import lru_cache from loguru import logger from reader import Entry, Feed, Reader, TagNotFoundError @@ -28,6 +29,7 @@ def get_images_from_entry(entry: Entry, summary: bool = False) -> list[str]: return re.findall(image_regex, convert_to_md(entry.content[0].value)) if entry.content else [] +@lru_cache() def try_to_replace(custom_message: str, template: str, replace_with: str) -> str: """Try to replace a tag in custom_message. @@ -56,6 +58,7 @@ def try_to_replace(custom_message: str, template: str, replace_with: str) -> str return custom_message +@lru_cache() def remove_image_tags(message: str) -> str: """Remove image tags from message. diff --git a/discord_rss_bot/settings.py b/discord_rss_bot/settings.py index e6efe7d..70da458 100644 --- a/discord_rss_bot/settings.py +++ b/discord_rss_bot/settings.py @@ -1,4 +1,5 @@ import os +from functools import lru_cache from loguru import logger from platformdirs import user_data_dir @@ -38,6 +39,7 @@ def get_webhook_for_entry(custom_reader: Reader, entry: Entry) -> str: return webhook_url +@lru_cache() def get_db_location(custom_location: str = "") -> str: """Where we store the database file. @@ -55,6 +57,7 @@ def get_db_location(custom_location: str = "") -> str: return db_loc +@lru_cache() def get_reader(custom_location: str = "") -> Reader: """Get the reader.