perf: add select narrowing to organization queries and error fetches
- cached-dashboard-data.ts: select only id, name from organizations (skips description, website, github_org_id, auto_add_github_members, etc.) - dashboard/action.ts getUserOrganizations: same select narrowing - members/action.ts getOrganizationMembers: select only id + nested members (skips all org metadata columns) - members/data.ts getMembersPageInitData: same select narrowing - llm-call/[id]/page.tsx: select only 6 rendered fields from optimization_errors (skips stack_trace Text column) - get-trace-data.ts: select only 4 consumed fields from optimization_errors (skips stack_trace, error_code, error_category, trace_id, llm_call_id)
This commit is contained in:
parent
b0eba5a87b
commit
6f9e81a690
6 changed files with 64 additions and 29 deletions
|
|
@ -22,7 +22,8 @@ export const getOrganizationMembers = withTiming(
|
|||
const [org, accessCheck] = await Promise.all([
|
||||
prisma.organizations.findUnique({
|
||||
where: { id: organizationId },
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
organization_members: {
|
||||
include: {
|
||||
user: { select: { user_id: true, github_username: true, name: true, email: true } },
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ export async function getMembersPageInitData() {
|
|||
// Single query fetches org with all members (including current user's role)
|
||||
const org = await prisma.organizations.findUnique({
|
||||
where: { id: orgId },
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
organization_members: {
|
||||
include: {
|
||||
user: {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ export async function getTraceData(tracePrefix: string) {
|
|||
prisma.optimization_errors.findMany({
|
||||
where: { trace_id: { startsWith: tracePrefix } },
|
||||
orderBy: { created_at: "asc" },
|
||||
select: {
|
||||
error_type: true,
|
||||
severity: true,
|
||||
error_message: true,
|
||||
context: true,
|
||||
},
|
||||
}),
|
||||
prisma.optimization_features.findFirst({
|
||||
where: { trace_id: { startsWith: tracePrefix } },
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
import Link from "next/link"
|
||||
import { Metadata } from "next"
|
||||
import { notFound } from "next/navigation"
|
||||
import {
|
||||
CheckCircle,
|
||||
XCircle,
|
||||
Hash,
|
||||
FileText,
|
||||
Code,
|
||||
AlertTriangle,
|
||||
} from "lucide-react"
|
||||
import { CheckCircle, XCircle, Hash, FileText, Code, AlertTriangle } from "lucide-react"
|
||||
import { prisma } from "@/lib/prisma"
|
||||
import { StatCard } from "@/components/observability/stat-card"
|
||||
import { InfoIcon } from "@/components/observability/info-icon"
|
||||
|
|
@ -22,7 +15,7 @@ interface LLMCallDetailPageProps {
|
|||
}
|
||||
|
||||
export async function generateMetadata(props: LLMCallDetailPageProps): Promise<Metadata> {
|
||||
const params = await props.params;
|
||||
const params = await props.params
|
||||
return {
|
||||
title: `LLM Call ${params.id.substring(0, 8)} - Observability`,
|
||||
description: "View LLM call details for prompt engineering analysis",
|
||||
|
|
@ -30,7 +23,7 @@ export async function generateMetadata(props: LLMCallDetailPageProps): Promise<M
|
|||
}
|
||||
|
||||
export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
||||
const params = await props.params;
|
||||
const params = await props.params
|
||||
// Fetch LLM call details and related errors in parallel
|
||||
const [llmCall, relatedErrors] = await Promise.all([
|
||||
prisma.llm_calls.findUnique({
|
||||
|
|
@ -39,6 +32,14 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
prisma.optimization_errors.findMany({
|
||||
where: { llm_call_id: params.id },
|
||||
orderBy: { created_at: "desc" },
|
||||
select: {
|
||||
id: true,
|
||||
error_type: true,
|
||||
severity: true,
|
||||
error_message: true,
|
||||
context: true,
|
||||
created_at: true,
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
|
|
@ -143,7 +144,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<span className="text-sm font-medium text-gray-600 dark:text-gray-400">
|
||||
Call Type
|
||||
</span>
|
||||
<InfoIcon content="Purpose of this LLM operation (optimization, validation, line_profiler, etc.)" side="top" />
|
||||
<InfoIcon
|
||||
content="Purpose of this LLM operation (optimization, validation, line_profiler, etc.)"
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<span className="font-semibold text-gray-900 dark:text-gray-100">
|
||||
{llmCall.call_type}
|
||||
|
|
@ -167,7 +171,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<span className="text-sm font-medium text-gray-600 dark:text-gray-400">
|
||||
Temperature
|
||||
</span>
|
||||
<InfoIcon content="Randomness setting (0=deterministic, 1=creative). Controls output variability." side="top" />
|
||||
<InfoIcon
|
||||
content="Randomness setting (0=deterministic, 1=creative). Controls output variability."
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<span className="font-semibold text-gray-900 dark:text-gray-100">
|
||||
{llmCall.temperature || "default"}
|
||||
|
|
@ -206,7 +213,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<span className="text-sm font-medium text-gray-600 dark:text-gray-400">
|
||||
Parsing Status
|
||||
</span>
|
||||
<InfoIcon content="Whether model output was successfully parsed into usable code candidates" side="top" />
|
||||
<InfoIcon
|
||||
content="Whether model output was successfully parsed into usable code candidates"
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<span
|
||||
className={`font-semibold ${
|
||||
|
|
@ -242,7 +252,7 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
{(() => {
|
||||
const promptTokens = llmCall.prompt_tokens ?? 0
|
||||
const completionTokens = llmCall.completion_tokens ?? 0
|
||||
const totalTokens = llmCall.total_tokens ?? (promptTokens + completionTokens)
|
||||
const totalTokens = llmCall.total_tokens ?? promptTokens + completionTokens
|
||||
// Use 1 as fallback only for division to prevent division by zero
|
||||
const safeTotalTokens = totalTokens || 1
|
||||
const promptPercent = Math.round((promptTokens / safeTotalTokens) * 100)
|
||||
|
|
@ -272,7 +282,7 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
{(() => {
|
||||
const promptTokens = llmCall.prompt_tokens ?? 0
|
||||
const completionTokens = llmCall.completion_tokens ?? 0
|
||||
const totalTokens = llmCall.total_tokens ?? (promptTokens + completionTokens)
|
||||
const totalTokens = llmCall.total_tokens ?? promptTokens + completionTokens
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -321,7 +331,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<div className="flex items-center gap-2 mb-4">
|
||||
<Code className="h-5 w-5 text-gray-600 dark:text-gray-400" />
|
||||
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">Parsing Results</h2>
|
||||
<InfoIcon content="Results from parsing the model's response into code candidates" side="top" />
|
||||
<InfoIcon
|
||||
content="Results from parsing the model's response into code candidates"
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<div>
|
||||
|
|
@ -368,7 +381,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5 text-gray-600 dark:text-gray-400" />
|
||||
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">System Prompt</h2>
|
||||
<InfoIcon content="Instructions that guide the model's behavior throughout the conversation" side="top" />
|
||||
<InfoIcon
|
||||
content="Instructions that guide the model's behavior throughout the conversation"
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-gray-500 dark:text-gray-400">
|
||||
|
|
@ -387,7 +403,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5 text-gray-600 dark:text-gray-400" />
|
||||
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">User Prompt</h2>
|
||||
<InfoIcon content="Specific task and context for this call. Contains the code to optimize and requirements." side="top" />
|
||||
<InfoIcon
|
||||
content="Specific task and context for this call. Contains the code to optimize and requirements."
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-gray-500 dark:text-gray-400">
|
||||
|
|
@ -408,7 +427,10 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<div className="flex items-center gap-2">
|
||||
<Code className="h-5 w-5 text-gray-600 dark:text-gray-400" />
|
||||
<h2 className="text-xl font-semibold text-gray-900 dark:text-white">LLM Response</h2>
|
||||
<InfoIcon content="Parsed view by call type: ranking shows order and explanation; optimization shows code blocks. Use View raw for the full string." side="top" />
|
||||
<InfoIcon
|
||||
content="Parsed view by call type: ranking shows order and explanation; optimization shows code blocks. Use View raw for the full string."
|
||||
side="top"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs text-gray-500 dark:text-gray-400">
|
||||
|
|
@ -417,10 +439,7 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
<CopyButton text={llmCall.raw_response} label="response" size="sm" />
|
||||
</div>
|
||||
</div>
|
||||
<ParsedResponseView
|
||||
rawResponse={llmCall.raw_response}
|
||||
callType={llmCall.call_type}
|
||||
/>
|
||||
<ParsedResponseView rawResponse={llmCall.raw_response} callType={llmCall.call_type} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
|
@ -435,7 +454,9 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
</div>
|
||||
<div className="mb-4">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">Error Type:</span>
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Error Type:
|
||||
</span>
|
||||
<span className="px-2 py-1 bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-300 rounded text-sm font-semibold">
|
||||
{llmCall.error_type}
|
||||
</span>
|
||||
|
|
@ -443,7 +464,9 @@ export default async function LLMCallDetailPage(props: LLMCallDetailPageProps) {
|
|||
</div>
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">Error Message:</span>
|
||||
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
Error Message:
|
||||
</span>
|
||||
<CopyButton text={llmCall.error_message} label="error message" size="sm" />
|
||||
</div>
|
||||
<pre className="bg-white dark:bg-gray-900 p-3 rounded-lg text-sm overflow-auto text-red-700 dark:text-red-400 border border-red-200 dark:border-red-800 font-mono leading-relaxed">
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ export async function getUserOrganizations(
|
|||
some: { user_id: userId },
|
||||
},
|
||||
},
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
organization_members: {
|
||||
where: { user_id: userId },
|
||||
select: { role: true },
|
||||
|
|
|
|||
|
|
@ -48,7 +48,9 @@ export async function getCachedDashboardData(userId: string): Promise<CachedDash
|
|||
some: { user_id: userId },
|
||||
},
|
||||
},
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
organization_members: {
|
||||
where: { user_id: userId },
|
||||
select: { role: true },
|
||||
|
|
|
|||
Loading…
Reference in a new issue