mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
aider: Switched both caches to use shelve
instead of json
.
# Context: USER: switch both caches to use shelve instead of json ASSISTANT: To switch both caches to use `shelve` instead of `json`, we need to modify the `aider/repomap.py` file. We will update the `load_tags_cache`, `save_tags_cache`, `load_ident_cache`, and `save_ident_cache` methods. Here are the changes: ```python aider/repomap.py <<<<<<< ORIGINAL import json ======= import shelve >>>>>>> UPDATED ``` ```python aider/repomap.py <<<<<<< ORIGINAL IDENT_CACHE_FILE = ".aider.ident.cache.json" TAGS_CACHE_FILE = ".aider.tags.cache.json" def load_tags_cache(self): if os.path.exists(self.TAGS_CACHE_FILE): with open(self.TAGS_CACHE_FILE, "r") as f: self.TAGS_CACHE = json.load(f) else: self.TAGS_CACHE = dict() def save_tags_cache(self): with open(self.TAGS_CACHE_FILE, "w") as f: json.dump(self.TAGS_CACHE, f) ======= IDENT_CACHE_FILE = ".aider.ident.cache" TAGS_CACHE_FILE = ".aider.tags.cache" def load_tags_cache(self): if os.path.exists(self.TAGS_CACHE_FILE): with shelve.open(self.TAGS_CACHE_FILE) as db: self.TAGS_CACHE = dict(db) else: self.TAGS_CACHE = dict() def save_tags_cache(self): with shelve.open(self.TAGS_CACHE_FILE) as db: db.update(self.TAGS_CACHE) >>>>>>> UPDATED ``` ```python aider/repomap.py <<<<<<< ORIGINAL def load_ident_cache(self): if os.path.exists(self.IDENT_CACHE_FILE): with open(self.IDENT_CACHE_FILE, "r") as f: self.IDENT_CACHE = json.load(f) else: self.IDENT_CACHE = dict() def save_ident_cache(self): with open(self.IDENT_CACHE_FILE, "w") as f: json.dump(self.IDENT_CACHE, f) ======= def load_ident_cache(self): if os.path.exists(self.IDENT_CACHE_FILE): with shelve.open(self.IDENT_CACHE_FILE) as db: self.IDENT_CACHE = dict(db) else: self.IDENT_CACHE = dict() def save_ident_cache(self): with shelve.open(self.IDENT_CACHE_FILE) as db: db.update(self.IDENT_CACHE) >>>>>>> UPDATED ``` These changes will replace the usage of `json` with `shelve` for both caches.
This commit is contained in:
parent
bd57c71898
commit
a9b53569ac
1 changed files with 11 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
import json
|
import shelve
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -52,19 +52,19 @@ def fname_to_components(fname, with_colon):
|
||||||
|
|
||||||
class RepoMap:
|
class RepoMap:
|
||||||
ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
|
ctags_cmd = ["ctags", "--fields=+S", "--extras=-F", "--output-format=json"]
|
||||||
IDENT_CACHE_FILE = ".aider.ident.cache.json"
|
IDENT_CACHE_FILE = ".aider.ident.cache"
|
||||||
TAGS_CACHE_FILE = ".aider.tags.cache.json"
|
TAGS_CACHE_FILE = ".aider.tags.cache"
|
||||||
|
|
||||||
def load_tags_cache(self):
|
def load_tags_cache(self):
|
||||||
if os.path.exists(self.TAGS_CACHE_FILE):
|
if os.path.exists(self.TAGS_CACHE_FILE):
|
||||||
with open(self.TAGS_CACHE_FILE, "r") as f:
|
with shelve.open(self.TAGS_CACHE_FILE) as db:
|
||||||
self.TAGS_CACHE = json.load(f)
|
self.TAGS_CACHE = dict(db)
|
||||||
else:
|
else:
|
||||||
self.TAGS_CACHE = dict()
|
self.TAGS_CACHE = dict()
|
||||||
|
|
||||||
def save_tags_cache(self):
|
def save_tags_cache(self):
|
||||||
with open(self.TAGS_CACHE_FILE, "w") as f:
|
with shelve.open(self.TAGS_CACHE_FILE) as db:
|
||||||
json.dump(self.TAGS_CACHE, f)
|
db.update(self.TAGS_CACHE)
|
||||||
|
|
||||||
def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
|
def __init__(self, use_ctags=None, root=None, main_model="gpt-4"):
|
||||||
if not root:
|
if not root:
|
||||||
|
@ -220,14 +220,14 @@ class RepoMap:
|
||||||
|
|
||||||
def load_ident_cache(self):
|
def load_ident_cache(self):
|
||||||
if os.path.exists(self.IDENT_CACHE_FILE):
|
if os.path.exists(self.IDENT_CACHE_FILE):
|
||||||
with open(self.IDENT_CACHE_FILE, "r") as f:
|
with shelve.open(self.IDENT_CACHE_FILE) as db:
|
||||||
self.IDENT_CACHE = json.load(f)
|
self.IDENT_CACHE = dict(db)
|
||||||
else:
|
else:
|
||||||
self.IDENT_CACHE = dict()
|
self.IDENT_CACHE = dict()
|
||||||
|
|
||||||
def save_ident_cache(self):
|
def save_ident_cache(self):
|
||||||
with open(self.IDENT_CACHE_FILE, "w") as f:
|
with shelve.open(self.IDENT_CACHE_FILE) as db:
|
||||||
json.dump(self.IDENT_CACHE, f)
|
db.update(self.IDENT_CACHE)
|
||||||
|
|
||||||
def get_name_identifiers(self, fname, uniq=True):
|
def get_name_identifiers(self, fname, uniq=True):
|
||||||
file_mtime = os.path.getmtime(fname)
|
file_mtime = os.path.getmtime(fname)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue