Skip to content

perf(organization): load org page from DB and reconcile controller in background#919

Open
evertoncustodio wants to merge 2 commits into
sinamics:mainfrom
evertoncustodio:feature/organization-loading
Open

perf(organization): load org page from DB and reconcile controller in background#919
evertoncustodio wants to merge 2 commits into
sinamics:mainfrom
evertoncustodio:feature/organization-loading

Conversation

@evertoncustodio

Copy link
Copy Markdown

What

The organization page (getOrgById) made one ZeroTier controller request
per member, sequentially. For large orgs (hundreds of networks) this made
the page take minutes to load.

Changes

  • Count authorized/total members directly from the network_members rows
    already fetched from the database (skipping deleted / permanently-deleted).
  • Move controller reconciliation — including the 404 orphan-member cleanup —
    to a fire-and-forget background task so it no longer blocks the response.
  • Add an in-flight guard so repeatedly opening the org page does not stack
    overlapping controller syncs.

Tests

  • Counts derive from the DB (controller reporting different values does not
    change them) and exclude deleted/permanently-deleted members.
  • The query resolves even when the controller never responds (non-blocking).
  • The background task deletes orphaned member rows on a 404.

Notes / trade-off

Counts reflect the DB's last-synced state. The authorized/deleted flags
are kept fresh by the per-network page (syncMemberPeersAndStatus); orphaned
members are removed within one page load by the background reconcile.

… background

getOrgById previously made one ZeroTier controller request per member
(sequentially), making the org page load extremely slow for large
organizations (minutes for hundreds of networks). Count authorized/total
members directly from the network_members rows already fetched from the
database, and move the controller reconciliation (including 404 orphan
cleanup) to a fire-and-forget background task so it no longer blocks the
response. An in-flight guard prevents overlapping syncs per organization.
@github-actions github-actions Bot added the ztnet Main Application label Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ztnet Main Application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant