perf(fulfillment): 修复 Outbox 状态版本去重、跨进程实时推送与数据库默认配置

This commit is contained in:
yml
2026-11-28 18:52:42 +08:00
parent f23ef42e67
commit d03eeaee18
22 changed files with 751 additions and 72 deletions
@@ -9,7 +9,7 @@ from dataclasses import dataclass
from datetime import UTC, datetime
from typing import Any
from sqlalchemy import or_
from sqlalchemy import func, or_
from sqlalchemy.orm import Session
from ...models import (
@@ -106,7 +106,12 @@ def _cached_task_count(
cached = engine_cache.get(key)
if cached and moment - cached[0] < _TASK_COUNT_CACHE_TTL_SECONDS:
return cached[1]
total = int(query.count())
total = int(
query.order_by(None)
.with_entities(func.count(PlatformFulfillmentTask.id))
.scalar()
or 0
)
with _TASK_COUNT_CACHE_LOCK:
engine_cache = _TASK_COUNT_CACHE.setdefault(bind, {})
if len(engine_cache) >= _TASK_COUNT_CACHE_MAX_ENTRIES: