You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 810a50e
Browse filesBrowse the repository at this point in the historyBrowse files
perf(sync): look up WorkOS user IDs through an indexed table (#50)
Finding the WP user for a WorkOS user ID (every sign-in and webhook, the WorkOS Users list, the role push) ran get_users() on the _workos_user_id meta. meta_value isn't indexed, so each lookup scanned every row with that key: ~40 ms on a site with 25,000 linked users, for hits and misses alike.
{base_prefix}workos_user_links mirrors the meta with the WorkOS ID as the key. The user meta hooks keep it in step with every write through the meta API, and the v4 schema upgrade fills it from the existing meta (25,000 rows in ~0.5 s). The meta stays the source of truth: each hit is checked against it, a stale row is repaired and answered from the meta, and lookups use the meta until the table is filled. Results match the get_users() query: users of the current site, the first by login when two carry one ID.
The WorkOS Users list resolves the whole page in two queries instead of one meta scan per row.
|`src/WorkOS/Sync/UserSync.php`| User sync (inbound/outbound) |
167
+
|`src/WorkOS/Sync/UserLinks.php`| WorkOS user ID → WP user lookups through `{base_prefix}workos_user_links` (indexed), mirrored from the `_workos_user_id` meta by the user meta hooks and filled by the v4 schema upgrade. `find()` / `find_many()` check every hit against the meta and use the meta until the table is filled (`workos_user_links_ready`). Writes to the meta that skip the meta API (raw SQL) aren't seen; `UserLinks::rebuild()` refills. |
167
168
|`src/WorkOS/Sync/RoleMapper.php`| WorkOS role → WP role mapping |
168
169
|`src/WorkOS/Sync/RoleSyncCheck.php`| Which members' WP role doesn't match the role map. Batched (one JOIN query per 1,000 members), run by "Check now" on WorkOS → Users or on an Action Scheduler schedule (`role_sync_schedule`: off/hourly/daily, only offered when AS is loaded). Stores the result in `workos_role_sync_check` (not autoloaded, stale when env/org/role map change) and rechecks single users on role and `workos_org_membership_changed`. Admin screens read `result()`; nothing is computed on page load. |
0 commit comments