Green Invoice access token is fetched on every request; client fires per-row request bursts

Aperta
#4,873 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
graphql, typescript

Direzione di ricerca

Start with packages/server/src/modules/app-providers/green-invoice-client.ts and packages/green-invoice-graphql/src/index.ts to trace token initialization and provider scope. For the request bursts, inspect Hive usage data for the reported minute and trace the matching operation to its page load; packages/server/src/modules/app-providers/tenant-db-client.ts shows the sequential query behavior. Done means one token request for two operations within an hour, with a fetch-injection test, and one request per page load instead of one per row.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Part of #4869.

1. A new Green Invoice token on every request

  • GreenInvoiceClientProvider is Scope.Operation (packages/server/src/modules/app-providers/green-invoice-client.ts:25).
  • So every operation that touches Green Invoice calls init() → obtainAccessToken() (packages/green-invoice-graphql/src/index.ts:4-29), an extra OAuth round trip each time.
  • On 2026-10-09, 10 one-hour tokens were minted in 36 minutes to serve 19 document fetches.

Fix:

  • Add an app-level (singleton) token cache keyed by the tenant's credentials ID.
  • Reuse a token until exp − 5 min.
  • Refresh with a single in-flight request at a time, and invalidate the cached token on a 401.
  • The operation-scoped provider reads its token from this cache.

2. The client fires per-row request bursts

  • At 07:43:07 UTC the client sent 74 GraphQL requests within one second, and 100 in that minute.
  • Each request holds its own pooled connection for its whole lifetime (pool max 20).
  • Each request also runs its queries one at a time on that connection (packages/server/src/modules/app-providers/tenant-db-client.ts:315). That is also why report requests take 8–9 s.
  • So a burst like this can saturate the pool on its own.

Fix: find the operation in Hive usage data for that minute. Then batch it into one query, or into a field on the parent list that a DataLoader can serve.

3. Expired Auth0 tokens

Tracked in #4490. For context:

  • Tokens arrived up to 31 minutes after their exp.
  • Bursts of up to 7 parallel requests failed together before the client refreshed (08:28:18 and 08:34:12 UTC).

Acceptance

  • Two Green Invoice operations within an hour make a single token request. Covered by a test that injects fetch.
  • The source of the burst is identified, and its page load issues one request instead of one per row.
Lingua principale
TypeScript
Stelle
30
Fork
9
Merge medio
1g 13h
PR unite (30g)
198

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Urigo/accounter-fullstack

Tutte le issue di Urigo/accounter-fullstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.