sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -9,6 +9,7 @@ from uuid import uuid4
from fastapi import APIRouter, HTTPException, Query, Request
from pydantic import BaseModel, Field
from app.gateway.api_read_cache import get_cache_version, get_cached_json, set_cached_json
from deerflow.runtime.user_context import get_effective_user_id
logger = logging.getLogger(__name__)
@@ -65,6 +66,16 @@ async def list_recommended_questions(
all: bool = Query(default=False, description="Admin management view: return every question, unfiltered by 岗位."),
tag_ids: list[str] | None = Query(default=None, description="Keep questions carrying any of these tags (OR)."),
) -> RecommendedQuestionsListResponse:
user_id = _current_user_id(request)
config = getattr(request.app.state, "config", None)
cache_key = f"user:{user_id}"
normalized_tag_ids = tag_ids if isinstance(tag_ids, list) else None
cacheable = not all and not normalized_tag_ids
version = await get_cache_version(config, "recommended_questions") if cacheable else None
if cacheable:
cached = await get_cached_json(config, "recommended_questions", cache_key, version=version)
if cached is not None:
return RecommendedQuestionsListResponse.model_validate(cached)
store = _get_store(request)
rows = await store.list_all()
responses = [RecommendedQuestionResponse(**r) for r in rows]
@@ -91,7 +102,7 @@ async def list_recommended_questions(
sync = getattr(request.app.state, "position_sync", None)
if sync is not None:
try:
visible = await sync.resolve_visible(_current_user_id(request), "recommended_question")
visible = await sync.resolve_visible(user_id, "recommended_question")
except Exception:
logger.debug("recommended-question visibility resolve failed", exc_info=True)
visible = None
@@ -100,11 +111,20 @@ async def list_recommended_questions(
else:
responses = [r for r in responses if not r.tags]
if tag_ids:
wanted = set(tag_ids)
if normalized_tag_ids:
wanted = set(normalized_tag_ids)
responses = [r for r in responses if any(t.get("id") in wanted for t in r.tags)]
return RecommendedQuestionsListResponse(questions=responses)
result = RecommendedQuestionsListResponse(questions=responses)
if cacheable:
await set_cached_json(
config,
"recommended_questions",
cache_key,
result,
expected_version=version,
)
return result
@router.post("/recommended-questions", response_model=RecommendedQuestionResponse, status_code=201)