Skip to content

Replace local cache dictionaries with functools.lru_cache#236

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/replace-local-caches-with-lru-cache
Closed

Replace local cache dictionaries with functools.lru_cache#236
Copilot wants to merge 3 commits intomainfrom
copilot/replace-local-caches-with-lru-cache

Conversation

Copy link

Copilot AI commented Dec 23, 2025

Replaces manual dictionary-based caching patterns with @lru_cache decorators for cleaner, more efficient memoization.

Changes

  • copy_text/text_bot.py, copy_to_en/medwiki.py, copy_to_en/mdwikicx.py:

    • Removed text_cache, revid_cache, un_wb_tag_cache dictionaries
    • Added @lru_cache(maxsize=128) to get_text_revid() and get_un_wb_tag()
    • Refactored get_un_wb_tag(x) to derive alltext from cached get_text_revid(x) instead of taking it as a parameter
  • wprefs/bots/replace_except.py:

    • Removed _regex_cache dictionary and _create_default_regexes() function
    • Split patterns into _DEFAULT_REGEXES (static) and _SITE_SPECIFIC_PATTERNS (require site data)
    • Added @lru_cache to _tag_regex() and new _compile_site_regex() functions

Not Changed

  • z/z_api/api_wrap.py: logins_cache is mutable state shared with external LoginWrap API, not a pure function cache

Example

# Before
text_cache = {}
def get_text_revid(x):
    alltext, revid = mdwiki_api.GetPageText(x, get_revid=True)
    text_cache[x] = alltext
    return alltext, revid

# After
@lru_cache(maxsize=128)
def get_text_revid(x):
    alltext, revid = mdwiki_api.GetPageText(x, get_revid=True)
    return alltext, revid
Original prompt

Replace all local cache dictionaries by functools cacheReplace all local cache dictionaries by functools lru_cache, You can also add functools lru_cache to some functions if it's will be helpful


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Important

Review skipped

Ignore keyword(s) in the title.

⛔ Ignored keywords (2)
  • WIP
  • DO NOT MERGE

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: MrIbrahem <26301308+MrIbrahem@users.noreply.github.com>
@MrIbrahem
Copy link
Collaborator

@copilot Replace all local cache (some of them has typo cash) dictionaries by functools cacheReplace all local cache dictionaries by functools lru_cache, You can also add functools lru_cache to some functions if it's will be helpful

Co-authored-by: MrIbrahem <26301308+MrIbrahem@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace local cache dictionaries with functools lru_cache Replace local cache dictionaries with functools.lru_cache Dec 23, 2025
Copilot AI requested a review from MrIbrahem December 23, 2025 10:55
@MrIbrahem MrIbrahem closed this Dec 24, 2025
@MrIbrahem MrIbrahem deleted the copilot/replace-local-caches-with-lru-cache branch December 24, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants