perf: optimize proxy streaming and database access
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
-- Performance-oriented projections and indexes for logs/workspace views.
|
||||
|
||||
CREATE INDEX IF NOT EXISTS proxy_logs_key_created_status_idx
|
||||
ON proxy_logs (downstream_api_key_id, created_at DESC, status);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS proxy_logs_key_model_created_idx
|
||||
ON proxy_logs (downstream_api_key_id, model_actual, created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS proxy_logs_content_summary_idx
|
||||
ON proxy_logs (content_summary);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS workspace_assets_user_output_created_idx
|
||||
ON workspace_assets (
|
||||
user_id,
|
||||
status,
|
||||
deleted_at,
|
||||
source,
|
||||
kind,
|
||||
created_at DESC
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS workspace_assets_output_role_created_idx
|
||||
ON workspace_assets (((metadata::jsonb #>> '{workspaceAsset,role}')), created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS workspace_assets_workflow_output_created_idx
|
||||
ON workspace_assets (((metadata::jsonb #>> '{workflowUi,type}')), created_at DESC);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS workspace_asset_daily (
|
||||
local_day TEXT NOT NULL,
|
||||
user_id BIGINT NOT NULL DEFAULT 0,
|
||||
source TEXT NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
asset_count BIGINT NOT NULL DEFAULT 0,
|
||||
local_file_count BIGINT NOT NULL DEFAULT 0,
|
||||
total_size_bytes BIGINT NOT NULL DEFAULT 0,
|
||||
created_at TEXT DEFAULT (CURRENT_TIMESTAMP::TEXT),
|
||||
updated_at TEXT DEFAULT (CURRENT_TIMESTAMP::TEXT),
|
||||
UNIQUE(local_day, user_id, source, kind)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS workspace_asset_daily_user_day_idx
|
||||
ON workspace_asset_daily (user_id, local_day DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS workspace_asset_daily_source_day_idx
|
||||
ON workspace_asset_daily (source, local_day DESC);
|
||||
Reference in New Issue
Block a user