Fix business plans
This commit is contained in:
@@ -3346,9 +3346,16 @@ class ComposeDrafts(LoginRequiredMixin, View):
|
||||
{
|
||||
"ok": True,
|
||||
"cached": False,
|
||||
"source": "fallback",
|
||||
"drafts": _fallback_drafts(),
|
||||
}
|
||||
)
|
||||
nocache = str(request.GET.get("nocache") or "").strip().lower() in {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
|
||||
last_ts = int(messages[-1].ts or 0)
|
||||
cache_key = _compose_ai_cache_key(
|
||||
@@ -3361,8 +3368,24 @@ class ComposeDrafts(LoginRequiredMixin, View):
|
||||
limit,
|
||||
)
|
||||
cached = cache.get(cache_key)
|
||||
if cached:
|
||||
return JsonResponse({"ok": True, "cached": True, "drafts": cached})
|
||||
if cached and not nocache:
|
||||
if isinstance(cached, dict):
|
||||
return JsonResponse(
|
||||
{
|
||||
"ok": True,
|
||||
"cached": True,
|
||||
"source": str(cached.get("source") or "unknown"),
|
||||
"drafts": list(cached.get("drafts") or []),
|
||||
}
|
||||
)
|
||||
return JsonResponse(
|
||||
{
|
||||
"ok": True,
|
||||
"cached": True,
|
||||
"source": "unknown",
|
||||
"drafts": list(cached or []),
|
||||
}
|
||||
)
|
||||
|
||||
ai_obj = AI.objects.filter(user=request.user).first()
|
||||
transcript = messages_to_string(
|
||||
@@ -3373,6 +3396,7 @@ class ComposeDrafts(LoginRequiredMixin, View):
|
||||
},
|
||||
)
|
||||
drafts = _fallback_drafts()
|
||||
source = "fallback"
|
||||
if ai_obj is not None:
|
||||
try:
|
||||
result = async_to_sync(ai_runner.run_prompt)(
|
||||
@@ -3386,11 +3410,18 @@ class ComposeDrafts(LoginRequiredMixin, View):
|
||||
parsed = _parse_draft_options(result)
|
||||
if parsed:
|
||||
drafts = parsed
|
||||
source = "ai"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
cache.set(cache_key, drafts, timeout=COMPOSE_AI_CACHE_TTL)
|
||||
return JsonResponse({"ok": True, "cached": False, "drafts": drafts})
|
||||
cache.set(
|
||||
cache_key,
|
||||
{"source": source, "drafts": drafts},
|
||||
timeout=COMPOSE_AI_CACHE_TTL,
|
||||
)
|
||||
return JsonResponse(
|
||||
{"ok": True, "cached": False, "source": source, "drafts": drafts}
|
||||
)
|
||||
|
||||
|
||||
class ComposeSummary(LoginRequiredMixin, View):
|
||||
|
||||
Reference in New Issue
Block a user