Skip to content

Commit

Permalink
better caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Dec 4, 2024
1 parent 389333b commit d9541c7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions coq/clients/lsp/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(
self._local_cached = _LocalCache()
self._working = Condition()
self._max_results = self._supervisor.match.max_results
self._cached_clients: AbstractSet[str] = set()
self._ex.run(self._poll())

def interrupt(self) -> None:
Expand Down Expand Up @@ -129,6 +130,18 @@ async def cont() -> None:
self._cache.set_cache(
{client: chunked}, skip_db=False
)
if context := self._supervisor.current_context:
cached_clients = self._cached_clients
async for lsp_comps in self._request(
context, cached_clients=cached_clients
):
if not self._work_lock.locked():
for chunked in batched(
lsp_comps.items, n=CACHE_CHUNK
):
self._cache.set_cache(
{lsp_comps.client: chunked}, skip_db=False
)

await self._with_interrupt(cont())

Expand All @@ -144,6 +157,7 @@ async def _work(self, context: Context) -> AsyncIterator[Completion]:
use_cache, cached_clients, cached = self._cache.apply_cache(
context, always=False
)
self._cached_clients = cached_clients
if not use_cache:
self._local_cached.pre.clear()
self._local_cached.post.clear()
Expand Down

0 comments on commit d9541c7

Please sign in to comment.