perf(reference-data): sweep the remaining raw reads onto the session cache, ratchet to 0 (#1941)

Final consumer migration of the responsiveness plan: the 35 files still
fetching fiscal periods, settings, accounts, cash accounts, dimensions or
templates on their own now read lib/reference-data, and every client
write site invalidates the shared cache instead of refetching locally.

Settings and registries: FiscalYearsManager, FiscalPeriodEditor (period
snapshotted once per company so a revalidation cannot reset dates being
edited), BookingTemplatesPanel, ChartOfAccounts, ChartOfAccountsManager,
EditAccountDialog, CorrectionEntryDialog, StrikeLinesDialog,
InvoicePaymentAccountsSettings; the dimensions registry (DimensionsManager,
DimensionCombobox, LineDimensionFields, DimensionFilter, bookkeeping/[id])
reads useDimensions and the ad-hoc fetchDimensions/fetchDimensionsCached
helpers are deleted.

Pages and pickers: CashAccountSelector (FyPicker-shaped restore, once per
company load), use-account-names, FiscalYearGapNotice,
OpeningBalancePeriodStep, BankFileConfirmStep, ImportReviewStep, the import
page (invalidates accounts + periods after a SIE execute), customers list,
invoices list + detail, pending, salary employee, asset dispose, year-end
and periodisering pages (invalidate periods after closing), reports
DimensionPnlView (its pivot picker read the wrong payload key and was
always empty; it now populates), SkatteverketPanel, TemplatePicker,
ArticleForm (vat_registered).

Invoice dialogs and extensions: SendInvoiceDialog, PaymentBookingDialog
(init reduced to the credit-note lookup + catalogue, proposal and voucher
preview fire on open when cached; a local getSession replaces the network
getUser for the fallback CC), InvoiceInboxWorkspace, TicWorkspace,
ArcimMigrationWorkspace (invalidates after each SIE import step),
enable-banking AccountPickerDialog.

raw-reference-fetch ratchet: 35 -> 0 files.

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-08-26 14:56:37 +02:00
committed by GitHub
co-authored by Jakob Wennberg Claude Fable 5
parent 4560ccbfc9
commit 3ee3565d6d
41 changed files with 636 additions and 977 deletions
+7 -25
View File
@@ -1,6 +1,6 @@
'use client'
import { useState, useMemo, useEffect } from 'react'
import { useState, useMemo } from 'react'
import { useTranslations } from 'next-intl'
import { Input } from '@/components/ui/input'
import { Badge } from '@/components/ui/badge'
@@ -17,7 +17,6 @@ import {
buildActiveAccountIndex,
searchAccounts,
type AccountSearchItem,
type ChartAccountLike,
} from '@/lib/bookkeeping/account-search'
import { formatAccountWithName } from '@/lib/bookkeeping/client-account-names'
import { isCounterpartyTemplateId } from '@/lib/bookkeeping/counterparty-templates'
@@ -25,7 +24,7 @@ import { convertLibraryToBookingTemplate, LIBRARY_TEMPLATE_PREFIX, isLibraryTemp
import { getAccountName } from '@/lib/bookkeeping/client-account-names'
import type { BookingTemplateLibrary, EntityType } from '@/types'
import type { SuggestedTemplate } from '@/lib/transactions/category-suggestions'
import { useBookingTemplates } from '@/lib/reference-data/hooks'
import { useAccounts, useBookingTemplates } from '@/lib/reference-data/hooks'
// Cap on the "Konton" search-result group: enough to cover sibling accounts
// on a number-prefix query without drowning the template results.
@@ -275,7 +274,11 @@ export default function TemplatePicker({
() => libraryTemplates.filter((tt) => !tt.is_system && tt.is_active),
[libraryTemplates],
)
const [chartAccounts, setChartAccounts] = useState<ChartAccountLike[]>([])
// The company's active chart, from the session cache (lib/reference-data),
// so the search field can surface real accounts (issue #1877) without a
// request per mount. buildActiveAccountIndex re-filters is_active as
// defense in depth. Only consulted when the consumer routes account picks.
const { accounts: chartAccounts } = useAccounts()
// Boolean gate rather than the callback itself: the parent recreates the
// handler every render, and depending on its identity would refetch the
// chart on each keystroke of the page underneath.
@@ -286,27 +289,6 @@ export default function TemplatePicker({
// and users know what they made).
const templateDirection = direction === 'income' ? 'income' : 'expense'
// Fetch the company's active chart so the search field can surface real
// accounts (issue #1877: an active konto like 5460 was unfindable because
// only template metadata was searched). The endpoint returns active
// accounts by default; buildActiveAccountIndex re-filters as defense in
// depth. Gated on the consumer actually routing account picks somewhere.
useEffect(() => {
if (!accountSearchEnabled) return
const controller = new AbortController()
;(async () => {
try {
const res = await fetch('/api/bookkeeping/accounts', { signal: controller.signal })
if (!res.ok) return
const { data } = await res.json() as { data?: ChartAccountLike[] }
if (data) setChartAccounts(data)
} catch (err) {
if (err instanceof DOMException && err.name === 'AbortError') return
}
})()
return () => { controller.abort() }
}, [accountSearchEnabled])
const accountIndex = useMemo(() => buildActiveAccountIndex(chartAccounts), [chartAccounts])
// Lazy convertibility map. A template is "convertible" if it fits the