Files
codex-proxy-rs/backend/migrations/0035_request_analytics_delete_invalidation.sql
T
ZyyandCodex cc69368f77 perf(store): scale request analytics and isolate request history (#389)
Build durable request facts and bounded aggregate queries, freeze historical
identities, and move recovery lease updates out of request history rows.
Align token fields across storage, APIs and pages.

Invalidate analytics only after actual request deletions and track embedded
migration inputs during builds.

Co-authored-by: Codex <noreply@openai.com>
2026-10-11 20:57:36 +08:00

15 lines
661 B
PL/PgSQL

-- 空清理不更新统计代次,避免与启动回填的快照事务发生无效写冲突
create or replace function invalidate_deleted_request_analytics() returns trigger language plpgsql as $$
begin
if exists (select 1 from deleted_requests) then
update request_analytics_build_state set generation = generation + 1 where singleton;
end if;
return null;
end
$$;
drop trigger request_analytics_delete_invalidation on model_requests;
create trigger request_analytics_delete_invalidation after delete on model_requests
referencing old table as deleted_requests
for each statement execute function invalidate_deleted_request_analytics();