Skip to content

Commit

Permalink
Add logic to repopulate mux cache in case a model changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Jan 30, 2025
1 parent a7629f5 commit f01d03e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/codegate/providers/crud/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from codegate.db.connection import DbReader, DbRecorder
from codegate.providers.base import BaseProvider
from codegate.providers.registry import ProviderRegistry, get_provider_registry
from codegate.workspaces import crud as workspace_crud

logger = structlog.get_logger("codegate")

Expand All @@ -32,6 +33,7 @@ class ProviderCrud:
def __init__(self):
self._db_reader = DbReader()
self._db_writer = DbRecorder()
self._ws_crud = workspace_crud.WorkspaceCrud()

async def list_endpoints(self) -> List[apimodelsv1.ProviderEndpoint]:
"""List all the endpoints."""
Expand Down Expand Up @@ -176,6 +178,9 @@ async def update_endpoint(
)
)

# a model might have been deleted, let's repopulate the cache
await self._ws_crud.repopulate_mux_cache()

return apimodelsv1.ProviderEndpoint.from_db_model(dbendpoint)

async def configure_auth_material(
Expand Down Expand Up @@ -208,6 +213,8 @@ async def delete_endpoint(self, provider_id: UUID):

await self._db_writer.delete_provider_endpoint(dbendpoint)

await self._ws_crud.repopulate_mux_cache()

async def models_by_provider(self, provider_id: UUID) -> List[apimodelsv1.ModelByProvider]:
"""Get the models by provider."""

Expand Down
5 changes: 5 additions & 0 deletions src/codegate/workspaces/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ async def initialize_mux_registry(self):
if active_ws:
self._mux_registry.set_active_workspace(active_ws.name)

return self.repopulate_mux_cache()

async def repopulate_mux_cache(self):
"""Repopulate the mux cache with all muxes in the database"""

# Get all workspaces
workspaces = await self.get_workspaces()

Expand Down

0 comments on commit f01d03e

Please sign in to comment.