feat(pitch-deck): add force recompute to bypass stale pitch_fm_results cache
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m1s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 27s
CI / test-python-voice (push) Successful in 25s
CI / test-bqas (push) Successful in 28s
All checks were successful
Build pitch-deck / build-push-deploy (push) Successful in 1m1s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 27s
CI / test-python-voice (push) Successful in 25s
CI / test-bqas (push) Successful in 28s
Adds `force: true` body param to POST /api/financial-model/compute that skips the cached results check and recomputes from assumptions directly. Exposes this via a "Force Recompute" button on the scenario edit admin page, so updating assumptions directly in the DB can be followed by a cache bust without touching the UI assumption flow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import { finanzplanToFMResults } from '@/lib/finanzplan/adapter'
|
|||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
const { scenarioId, source } = body
|
const { scenarioId, source, force } = body
|
||||||
|
|
||||||
// If source=finanzplan, use the Finanzplan engine instead
|
// If source=finanzplan, use the Finanzplan engine instead
|
||||||
if (source === 'finanzplan') {
|
if (source === 'finanzplan') {
|
||||||
@@ -28,8 +28,8 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
const client = await pool.connect()
|
const client = await pool.connect()
|
||||||
try {
|
try {
|
||||||
// Fast path: return cached results if they exist (avoid expensive recompute + 60 inserts)
|
// Fast path: return cached results if they exist (skip when force=true)
|
||||||
const cached = await client.query(
|
const cached = force ? { rows: [] } : await client.query(
|
||||||
'SELECT * FROM pitch_fm_results WHERE scenario_id = $1 ORDER BY month',
|
'SELECT * FROM pitch_fm_results WHERE scenario_id = $1 ORDER BY month',
|
||||||
[scenarioId]
|
[scenarioId]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { ArrowLeft, Save } from 'lucide-react'
|
import { ArrowLeft, RefreshCw, Save } from 'lucide-react'
|
||||||
|
|
||||||
interface Assumption {
|
interface Assumption {
|
||||||
id: string
|
id: string
|
||||||
@@ -36,6 +36,7 @@ export default function EditScenarioPage() {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [edits, setEdits] = useState<Record<string, string>>({})
|
const [edits, setEdits] = useState<Record<string, string>>({})
|
||||||
const [savingId, setSavingId] = useState<string | null>(null)
|
const [savingId, setSavingId] = useState<string | null>(null)
|
||||||
|
const [recomputing, setRecomputing] = useState(false)
|
||||||
const [toast, setToast] = useState<string | null>(null)
|
const [toast, setToast] = useState<string | null>(null)
|
||||||
|
|
||||||
function flashToast(msg: string) {
|
function flashToast(msg: string) {
|
||||||
@@ -56,6 +57,17 @@ export default function EditScenarioPage() {
|
|||||||
|
|
||||||
useEffect(() => { if (scenarioId) load() }, [scenarioId])
|
useEffect(() => { if (scenarioId) load() }, [scenarioId])
|
||||||
|
|
||||||
|
async function forceRecompute() {
|
||||||
|
setRecomputing(true)
|
||||||
|
const res = await fetch('/api/financial-model/compute', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ scenarioId, force: true }),
|
||||||
|
})
|
||||||
|
setRecomputing(false)
|
||||||
|
flashToast(res.ok ? 'Recomputed successfully' : 'Recompute failed')
|
||||||
|
}
|
||||||
|
|
||||||
function setEdit(id: string, val: string) {
|
function setEdit(id: string, val: string) {
|
||||||
setEdits(prev => ({ ...prev, [id]: val }))
|
setEdits(prev => ({ ...prev, [id]: val }))
|
||||||
}
|
}
|
||||||
@@ -108,17 +120,28 @@ export default function EditScenarioPage() {
|
|||||||
<ArrowLeft className="w-4 h-4" /> Back to scenarios
|
<ArrowLeft className="w-4 h-4" /> Back to scenarios
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<div>
|
<div className="flex items-start justify-between gap-4">
|
||||||
<div className="flex items-center gap-3 mb-1">
|
<div>
|
||||||
<div className="w-4 h-4 rounded-full" style={{ backgroundColor: scenario.color }} />
|
<div className="flex items-center gap-3 mb-1">
|
||||||
<h1 className="text-2xl font-semibold text-white">{scenario.name}</h1>
|
<div className="w-4 h-4 rounded-full" style={{ backgroundColor: scenario.color }} />
|
||||||
{scenario.is_default && (
|
<h1 className="text-2xl font-semibold text-white">{scenario.name}</h1>
|
||||||
<span className="text-[9px] px-1.5 py-0.5 rounded bg-indigo-500/20 text-indigo-300 uppercase font-semibold">
|
{scenario.is_default && (
|
||||||
Default
|
<span className="text-[9px] px-1.5 py-0.5 rounded bg-indigo-500/20 text-indigo-300 uppercase font-semibold">
|
||||||
</span>
|
Default
|
||||||
)}
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{scenario.description && <p className="text-sm text-white/50">{scenario.description}</p>}
|
||||||
</div>
|
</div>
|
||||||
{scenario.description && <p className="text-sm text-white/50">{scenario.description}</p>}
|
<button
|
||||||
|
onClick={forceRecompute}
|
||||||
|
disabled={recomputing}
|
||||||
|
className="flex items-center gap-2 text-sm px-3 py-1.5 rounded-lg bg-white/[0.06] hover:bg-white/[0.1] text-white/70 hover:text-white disabled:opacity-40 disabled:cursor-wait transition-colors"
|
||||||
|
title="Clear cache and recompute financial model results"
|
||||||
|
>
|
||||||
|
<RefreshCw className={`w-3.5 h-3.5 ${recomputing ? 'animate-spin' : ''}`} />
|
||||||
|
{recomputing ? 'Computing…' : 'Force Recompute'}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
|||||||
Reference in New Issue
Block a user