mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Prefetch the settings and openai_config of a texttoimagemodelconfig
This commit is contained in:
parent
132eac0f51
commit
9306a0bb2c
1 changed files with 7 additions and 2 deletions
|
@ -14,7 +14,7 @@ from apscheduler.job import Job
|
|||
from asgiref.sync import sync_to_async
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.db.models import Prefetch, Q
|
||||
from django.db.models.manager import BaseManager
|
||||
from django.db.utils import IntegrityError
|
||||
from django_apscheduler.models import DjangoJob, DjangoJobExecution
|
||||
|
@ -989,7 +989,12 @@ class ConversationAdapters:
|
|||
|
||||
@staticmethod
|
||||
async def aget_user_text_to_image_model(user: KhojUser) -> Optional[TextToImageModelConfig]:
|
||||
config = await UserTextToImageModelConfig.objects.filter(user=user).prefetch_related("setting").afirst()
|
||||
# Create a custom queryset for prefetching settings__openai_config, handling null cases
|
||||
settings_prefetch = Prefetch(
|
||||
"setting", queryset=TextToImageModelConfig.objects.prefetch_related("openai_config")
|
||||
)
|
||||
|
||||
config = await UserTextToImageModelConfig.objects.filter(user=user).prefetch_related(settings_prefetch).afirst()
|
||||
if not config:
|
||||
default_config = await ConversationAdapters.aget_text_to_image_model_config()
|
||||
if not default_config:
|
||||
|
|
Loading…
Reference in a new issue