mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-21 18:22:03 +00:00
合入 W2-a 的复核修复(nr8/a:导入的 NOT NULL 补值与孤儿行、收尾 dispose、sslmode 换算、PostgreSQL 写入去 NUL、不分大小写搜索 contains_ci、json_eq 两库同语义、JSON 守卫、用户可见列表补决胜键、bubblewrap --clearenv、部署脚本与原子写的几处、README 连接数预算)
# Conflicts: # backend/app/api/schedules.py # backend/app/main.py
This commit is contained in:
@@ -142,7 +142,7 @@ async def active_job(session: AsyncSession, source_id: str) -> CatalogDraftJob |
|
||||
"""排队或进行中的那个(同一个源最多一个)。"""
|
||||
return (await session.execute(
|
||||
select(CatalogDraftJob).where(CatalogDraftJob.source_id == source_id, CatalogDraftJob.status.in_(ACTIVE))
|
||||
.order_by(CatalogDraftJob.created_at.desc()).limit(1)
|
||||
.order_by(CatalogDraftJob.created_at.desc(), CatalogDraftJob.id.desc()).limit(1)
|
||||
)).scalar_one_or_none()
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ async def latest_job(session: AsyncSession, source_id: str) -> CatalogDraftJob |
|
||||
"""最近建的一个(任何状态)。"""
|
||||
return (await session.execute(
|
||||
select(CatalogDraftJob).where(CatalogDraftJob.source_id == source_id)
|
||||
.order_by(CatalogDraftJob.created_at.desc()).limit(1)
|
||||
.order_by(CatalogDraftJob.created_at.desc(), CatalogDraftJob.id.desc()).limit(1)
|
||||
)).scalar_one_or_none()
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ async def last_drafts(session: AsyncSession, source_id: str) -> dict[str, dict[s
|
||||
中断了、而且没有写进新内容(parts_written 为 0)时照样带着,界面据此继续提示留空的列;之后有起草写进了新内容(停止
|
||||
前已经写了几段、或者正在写)就是 null:以前的留空列数可能已经不对了。不用模型的起草不改模型留空的列,不算。"""
|
||||
recent = (select(CatalogDraftJob.id).where(CatalogDraftJob.source_id == source_id)
|
||||
.order_by(CatalogDraftJob.created_at.desc()).limit(LAST_DRAFT_JOBS)).scalar_subquery()
|
||||
.order_by(CatalogDraftJob.created_at.desc(), CatalogDraftJob.id.desc()).limit(LAST_DRAFT_JOBS)).scalar_subquery()
|
||||
|
||||
def ranked() -> Any:
|
||||
return func.row_number().over(partition_by=CatalogDraftTask.table_name,
|
||||
|
||||
@@ -127,7 +127,7 @@ async def active_job(session: AsyncSession, source_id: str) -> CatalogProfileJob
|
||||
return (await session.execute(
|
||||
select(CatalogProfileJob).where(CatalogProfileJob.source_id == source_id,
|
||||
CatalogProfileJob.status.in_(ACTIVE))
|
||||
.order_by(CatalogProfileJob.created_at.desc()).limit(1)
|
||||
.order_by(CatalogProfileJob.created_at.desc(), CatalogProfileJob.id.desc()).limit(1)
|
||||
)).scalar_one_or_none()
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ async def latest_job(session: AsyncSession, source_id: str) -> CatalogProfileJob
|
||||
"""最近建的一个(任何状态)。"""
|
||||
return (await session.execute(
|
||||
select(CatalogProfileJob).where(CatalogProfileJob.source_id == source_id)
|
||||
.order_by(CatalogProfileJob.created_at.desc()).limit(1)
|
||||
.order_by(CatalogProfileJob.created_at.desc(), CatalogProfileJob.id.desc()).limit(1)
|
||||
)).scalar_one_or_none()
|
||||
|
||||
|
||||
|
||||
@@ -505,7 +505,7 @@ async def observed_facts(session: AsyncSession, source_id: str,
|
||||
query = query.where(TableObservation.table_name.in_(wanted))
|
||||
out: dict[str, dict[str, Any]] = {}
|
||||
seen: set[tuple[str, str, str]] = set()
|
||||
for r in (await session.execute(query.order_by(TableObservation.at.desc()))).scalars():
|
||||
for r in (await session.execute(query.order_by(TableObservation.at.desc(), TableObservation.id.desc()))).scalars():
|
||||
key = (r.table_name, r.kind, r.column_name)
|
||||
if key in seen:
|
||||
continue
|
||||
|
||||
@@ -104,13 +104,13 @@ def _iso(value: Any) -> str | None:
|
||||
async def active_job(session: AsyncSession, source_id: str) -> IntrospectJob | None:
|
||||
return (await session.execute(
|
||||
select(IntrospectJob).where(IntrospectJob.source_id == source_id, IntrospectJob.status.in_(ACTIVE))
|
||||
.order_by(IntrospectJob.created_at.desc()).limit(1))).scalar_one_or_none()
|
||||
.order_by(IntrospectJob.created_at.desc(), IntrospectJob.id.desc()).limit(1))).scalar_one_or_none()
|
||||
|
||||
|
||||
async def latest_job(session: AsyncSession, source_id: str) -> IntrospectJob | None:
|
||||
return (await session.execute(
|
||||
select(IntrospectJob).where(IntrospectJob.source_id == source_id)
|
||||
.order_by(IntrospectJob.created_at.desc()).limit(1))).scalar_one_or_none()
|
||||
.order_by(IntrospectJob.created_at.desc(), IntrospectJob.id.desc()).limit(1))).scalar_one_or_none()
|
||||
|
||||
|
||||
async def load(session: AsyncSession, source_id: str, job_id: str) -> IntrospectJob | None:
|
||||
@@ -437,7 +437,7 @@ async def _record_scope_changes(session: AsyncSession, row: Any, job: Introspect
|
||||
select(IntrospectJob).where(IntrospectJob.source_id == job.source_id, IntrospectJob.id != job.id,
|
||||
IntrospectJob.started_at.is_not(None),
|
||||
IntrospectJob.created_at <= job.created_at)
|
||||
.order_by(IntrospectJob.created_at.desc()).limit(1))).scalar_one_or_none()
|
||||
.order_by(IntrospectJob.created_at.desc(), IntrospectJob.id.desc()).limit(1))).scalar_one_or_none()
|
||||
before = (previous.scope or {}).get("rules") if previous is not None else None
|
||||
after = (job.scope or {}).get("rules")
|
||||
if isinstance(before, dict) and isinstance(after, dict) and before != after:
|
||||
|
||||
@@ -241,7 +241,7 @@ async def schedules_for(session: Any, source_id: str) -> list[dict[str, Any]]:
|
||||
|
||||
rows = (await session.execute(select(Schedule).where(
|
||||
Schedule.target_kind == "source_maintenance", Schedule.target_id == source_id)
|
||||
.order_by(Schedule.created_at))).scalars()
|
||||
.order_by(Schedule.created_at, Schedule.id))).scalars()
|
||||
return [{"id": r.id, "name": r.name, "cron": r.cron, "timezone": r.timezone, "enabled": r.enabled,
|
||||
"next_run_at": r.next_run_at.isoformat() if r.next_run_at else None} for r in rows]
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ from app.core.errors import describe_exception, first_line
|
||||
from app.data.names import name_key
|
||||
from app.db.base import SessionLocal, utcnow
|
||||
from app.db.models_sources import SourceObject
|
||||
from app.db.portable import contains_ci
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -879,9 +880,8 @@ async def search_index(session: AsyncSession, row: Any, query: str, *, limit: in
|
||||
return [], 0
|
||||
key = name_key(text.rsplit(".", 1)[-1])
|
||||
filt = (*_scope_filter(row.id, index_schema(row)), SourceObject.removed_at.is_(None),
|
||||
# 名字比的是 name_key(ASCII 已转小写);注释要不分大小写:SQLite 的 LIKE 本来就不分(ASCII),PostgreSQL 分
|
||||
or_(SourceObject.name_key.contains(key, autoescape=True),
|
||||
SourceObject.comment.icontains(text, autoescape=True)))
|
||||
# 名字比的是 name_key(ASCII 已转小写);注释要不分大小写(db/portable.contains_ci:两种库都折 Unicode 的大小写)
|
||||
or_(SourceObject.name_key.contains(key, autoescape=True), contains_ci(SourceObject.comment, text)))
|
||||
total = int((await session.execute(select(func.count()).select_from(SourceObject).where(*filt))).scalar() or 0)
|
||||
rows = (await session.execute(
|
||||
select(SourceObject.name, SourceObject.name_key, SourceObject.kind, SourceObject.comment,
|
||||
|
||||
@@ -1996,7 +1996,7 @@ async def _release_raws_locked(session: AsyncSession, shas: set[str]) -> set[str
|
||||
async def _expire_stagings_locked(session: AsyncSession, now: datetime) -> list[str]:
|
||||
"""(持锁)过期的暂存区 → expired、瘦身、删试运行库、放掉没人要的原件;结束超过 90 天的行删掉(提交)。"""
|
||||
expired = list((await session.execute(
|
||||
select(ImportStaging).where(_expiry_due(now)).order_by(ImportStaging.created_at)
|
||||
select(ImportStaging).where(_expiry_due(now)).order_by(ImportStaging.created_at, ImportStaging.id)
|
||||
)).scalars())
|
||||
ids, shas = [s.id for s in expired], {s.raw_sha256 for s in expired}
|
||||
trials = [close_staging(s, "expired", now=now) for s in expired]
|
||||
@@ -2177,7 +2177,7 @@ async def purge_import_raw(
|
||||
stagings = list((await session.execute(
|
||||
select(ImportStaging).where(
|
||||
ImportStaging.raw_sha256 == sha, ImportStaging.status.in_(STAGING_OPEN),
|
||||
).order_by(ImportStaging.created_at)
|
||||
).order_by(ImportStaging.created_at, ImportStaging.id)
|
||||
)).scalars()) if sha else []
|
||||
now = utcnow()
|
||||
record = {
|
||||
|
||||
Reference in New Issue
Block a user