mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-15 10:43:07 +00:00
- ~190 findings zerados: knip --fix (grafo corrigido: tests como entries, migrations como consumidores) + delecao guardada dos orfaos (git grep -w antes de deletar) + reparos manuais dos corpos arrow pendurados - pecas nao usadas do kit ui deletadas (PaginationLink/Next/Previous, familias Sidebar/Combobox/Sheet/Drawer/Dialog etc.) - shadcn add recoloca se precisar - acoes mortas removidas (updateCampaignDemandDetails*, *Record orfaos), schemas/tipos mortos (campaignDemandDetailsUpdateSchema, Contact do zod), helpers mortos - tipos de eleicao derivam direto das *_OPTIONS (consts intermediarias eliminadas) - knip.json: rules exports/types/enumMembers=error, duplicates=off (unicos hits: 6 aliases deliberados canUpdateX=canReadX); hints aplicados (payload.config entry redundante, ignores de tsx/sharp/playwright/payload-types desnecessarios) - ledger: linha P2 dos unused exports fechada
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import 'server-only'
|
|
|
|
import type { Config } from '@/payload-types'
|
|
|
|
import configPromise from '@payload-config'
|
|
import { revalidateTag, unstable_cache } from 'next/cache'
|
|
import { getPayload } from 'payload'
|
|
|
|
type Global = keyof Config['globals']
|
|
|
|
async function getGlobal<Slug extends Global>(slug: Slug, depth?: number) {
|
|
const payload = await getPayload({ config: configPromise })
|
|
|
|
const global = await payload.findGlobal({
|
|
slug,
|
|
depth,
|
|
})
|
|
|
|
return global
|
|
}
|
|
|
|
export const getGlobalCacheTag = (slug: string) => `global_${slug}`
|
|
|
|
type CachedGlobalFactory<Slug extends Global = Global> = () => Promise<Config['globals'][Slug]>
|
|
|
|
const cachedGlobalFactories = new Map<string, CachedGlobalFactory>()
|
|
|
|
export const getCachedGlobal = <Slug extends Global>(slug: Slug, depth?: number) => {
|
|
const tag = getGlobalCacheTag(slug)
|
|
const cacheKey = `${tag}:${depth ?? 0}`
|
|
const existing = cachedGlobalFactories.get(cacheKey) as CachedGlobalFactory<Slug> | undefined
|
|
if (existing) return existing
|
|
|
|
const factory = unstable_cache(async () => getGlobal(slug, depth), [cacheKey], {
|
|
tags: [tag],
|
|
}) as CachedGlobalFactory<Slug>
|
|
cachedGlobalFactories.set(cacheKey, factory as CachedGlobalFactory)
|
|
return factory
|
|
}
|
|
|
|
export const revalidateGlobal = <Slug extends Global>(slug: Slug) =>
|
|
revalidateTag(getGlobalCacheTag(slug))
|