Skip to content

Commit

Permalink
Refactor: prefetch app document from base_db and cleanup db_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed May 15, 2024
1 parent 33fd48c commit da4cdf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion agenta-backend/agenta_backend/routers/configs_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
db_manager,
app_manager,
)
from agenta_backend.models.db_models import VariantBaseDB

if isCloudEE():
from agenta_backend.commons.models.db_models import Permission
Expand Down Expand Up @@ -93,7 +94,7 @@ async def get_config(
try:
base_db = await db_manager.fetch_base_by_id(base_id)

# detemine whether the user has access to the base
# determine whether the user has access to the base
if isCloudEE():
has_permission = await check_action_access(
user_uid=request.state.user_id,
Expand All @@ -110,6 +111,7 @@ async def get_config(

# in case environment_name is provided, find the variant deployed
if environment_name:
await base_db.fetch_link(VariantBaseDB.app)
app_environments = await db_manager.list_environments(
app_id=str(base_db.app.id)
)
Expand Down
7 changes: 5 additions & 2 deletions agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,15 @@ async def fetch_base_by_id(base_id: str) -> Optional[VariantBaseDB]:
Returns:
VariantBaseDB: The fetched base, or None if no base was found.
"""

if base_id is None:
raise Exception("No base_id provided")

base = await VariantBaseDB.find_one(VariantBaseDB.id == ObjectId(base_id))
if base is None:
if not base:
logger.error("Base not found")
return False
return None

return base


Expand Down

0 comments on commit da4cdf3

Please sign in to comment.