优化已发现问题
This commit is contained in:
@@ -13,6 +13,8 @@ from __future__ import annotations
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from django.db.models import Q
|
||||
|
||||
from apps.assets.models import Asset, Model
|
||||
from apps.products.models import Product
|
||||
|
||||
@@ -72,11 +74,15 @@ def _search_products(team, q: str, limit: int) -> list[dict]:
|
||||
|
||||
|
||||
def _search_models(team, q: str, limit: int) -> list[dict]:
|
||||
queryset = Model.objects.filter(team=team, is_deleted=False, purged_at__isnull=True)
|
||||
queryset = Model.objects.filter(
|
||||
Q(team=team) | Q(is_official=True),
|
||||
is_deleted=False,
|
||||
purged_at__isnull=True,
|
||||
)
|
||||
if q:
|
||||
queryset = queryset.filter(name__icontains=q)
|
||||
out = []
|
||||
for model in queryset.select_related("portrait_asset").order_by("-created_at")[:limit]:
|
||||
for model in queryset.select_related("portrait_asset").order_by("-is_official", "-created_at")[:limit]:
|
||||
out.append(_ref("model", model.id, model.name, _asset_preview_url(model.portrait_asset)))
|
||||
return out
|
||||
|
||||
@@ -173,7 +179,12 @@ def lookup_mention(team, value: str, types: list[str] | None = None) -> dict | N
|
||||
return _ref("product", product.id, product.title, _product_cover_url(product))
|
||||
if "model" in wanted:
|
||||
model = (
|
||||
Model.objects.filter(team=team, id=uid, is_deleted=False, purged_at__isnull=True)
|
||||
Model.objects.filter(
|
||||
Q(team=team) | Q(is_official=True),
|
||||
id=uid,
|
||||
is_deleted=False,
|
||||
purged_at__isnull=True,
|
||||
)
|
||||
.select_related("portrait_asset")
|
||||
.first()
|
||||
)
|
||||
@@ -384,7 +395,10 @@ def resolve_refs(team, refs: list[dict]) -> ResolvedRefs:
|
||||
continue
|
||||
if type_ == "model":
|
||||
model = Model.objects.filter(
|
||||
team=team, id=ref_id, is_deleted=False, purged_at__isnull=True
|
||||
Q(team=team) | Q(is_official=True),
|
||||
id=ref_id,
|
||||
is_deleted=False,
|
||||
purged_at__isnull=True,
|
||||
).select_related("triview_asset", "portrait_asset").first()
|
||||
if model is None:
|
||||
resolved.missing.append(ref)
|
||||
|
||||
Reference in New Issue
Block a user