mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
refactor: Modify cache warming mechanism with ok_to_warm_cache flag
This commit is contained in:
parent
35f30bde04
commit
f7dd0fc582
2 changed files with 10 additions and 8 deletions
|
@ -168,6 +168,7 @@ class Coder:
|
||||||
use_kwargs.update(kwargs) # override passed kwargs
|
use_kwargs.update(kwargs) # override passed kwargs
|
||||||
|
|
||||||
kwargs = use_kwargs
|
kwargs = use_kwargs
|
||||||
|
from_coder.ok_to_warm_cache = False
|
||||||
|
|
||||||
for coder in coders.__all__:
|
for coder in coders.__all__:
|
||||||
if hasattr(coder, "edit_format") and coder.edit_format == edit_format:
|
if hasattr(coder, "edit_format") and coder.edit_format == edit_format:
|
||||||
|
@ -264,7 +265,7 @@ class Coder:
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
_cache_warming_stop = False
|
ok_to_warm_cache = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -1198,25 +1199,23 @@ class Coder:
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
def warm_cache(self, chunks):
|
def warm_cache(self, chunks):
|
||||||
dump(self.add_cache_headers)
|
|
||||||
dump(self.num_cache_warming_pings)
|
|
||||||
if not self.add_cache_headers:
|
if not self.add_cache_headers:
|
||||||
return
|
return
|
||||||
if not self.num_cache_warming_pings:
|
if not self.num_cache_warming_pings:
|
||||||
return
|
return
|
||||||
|
if not self.ok_to_warm_cache:
|
||||||
|
return
|
||||||
|
|
||||||
delay = 5 # * 60 - 5
|
delay = 5 * 60 - 5
|
||||||
self.next_cache_warm = time.time() + delay
|
self.next_cache_warm = time.time() + delay
|
||||||
self.warming_pings_left = self.num_cache_warming_pings
|
self.warming_pings_left = self.num_cache_warming_pings
|
||||||
self.cache_warming_chunks = chunks
|
self.cache_warming_chunks = chunks
|
||||||
self._cache_warming_stop = False
|
|
||||||
|
|
||||||
if self.cache_warming_thread:
|
if self.cache_warming_thread:
|
||||||
return
|
return
|
||||||
|
|
||||||
def warm_cache_worker():
|
def warm_cache_worker():
|
||||||
while not self._cache_warming_stop:
|
while self.ok_to_warm_cache:
|
||||||
dump(self.warming_pings_left)
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if self.warming_pings_left <= 0:
|
if self.warming_pings_left <= 0:
|
||||||
continue
|
continue
|
||||||
|
@ -1543,7 +1542,7 @@ class Coder:
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""Cleanup when the Coder object is destroyed."""
|
"""Cleanup when the Coder object is destroyed."""
|
||||||
self._cache_warming_stop = True
|
self.ok_to_warm_cache = False
|
||||||
|
|
||||||
def add_assistant_reply_to_cur_messages(self):
|
def add_assistant_reply_to_cur_messages(self):
|
||||||
if self.partial_response_content:
|
if self.partial_response_content:
|
||||||
|
|
|
@ -1060,10 +1060,13 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
coder.ok_to_warm_cache = True
|
||||||
coder.run()
|
coder.run()
|
||||||
analytics.event("exit", reason="Completed main CLI coder.run")
|
analytics.event("exit", reason="Completed main CLI coder.run")
|
||||||
return
|
return
|
||||||
except SwitchCoder as switch:
|
except SwitchCoder as switch:
|
||||||
|
coder.ok_to_warm_cache = False
|
||||||
|
|
||||||
kwargs = dict(io=io, from_coder=coder)
|
kwargs = dict(io=io, from_coder=coder)
|
||||||
kwargs.update(switch.kwargs)
|
kwargs.update(switch.kwargs)
|
||||||
if "show_announcements" in kwargs:
|
if "show_announcements" in kwargs:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue