Skip to content

Commit 4b77caf

Browse files
committed
fix(people): read a page and its managers from one snapshot
1 parent 62af64f commit 4b77caf

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

‎apps/sim/lib/people/repository.ts‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ const SEARCHED_COLUMNS = [
118118
memberProfile.location,
119119
]
120120

121-
/** A page of people by name, then membership id, so equal names still page stably. */
121+
/**
122+
* A page of people by name, then membership id, so equal names still page stably. The page and
123+
* its managers come from one snapshot, so a manager shown always matches the profile listed.
124+
*/
122125
export async function listPeople(
123126
organizationId: string,
124127
{
@@ -128,17 +131,22 @@ export async function listPeople(
128131
}: { search?: string; department?: string; cursorKeys?: CursorKey[] }
129132
): Promise<KeysetPage<PersonRecord>> {
130133
const term = search?.trim() || undefined
131-
const rows = await selectPeople(
132-
db,
133-
organizationId,
134-
term ? or(...SEARCHED_COLUMNS.map((column) => searchFilter(column, term))) : undefined,
135-
department ? eq(memberProfile.department, department) : undefined,
136-
resumeKeyset(PEOPLE_KEYS, cursorKeys, 'asc')
134+
return db.transaction(
135+
async (tx) => {
136+
const rows = await selectPeople(
137+
tx,
138+
organizationId,
139+
term ? or(...SEARCHED_COLUMNS.map((column) => searchFilter(column, term))) : undefined,
140+
department ? eq(memberProfile.department, department) : undefined,
141+
resumeKeyset(PEOPLE_KEYS, cursorKeys, 'asc')
142+
)
143+
.orderBy(...keysetOrderBy(PEOPLE_KEYS, 'asc'))
144+
.limit(PAGE_SIZE + 1)
145+
const page = keysetPage(PEOPLE_KEYS, rows, PAGE_SIZE)
146+
return { ...page, data: await withManagers(tx, organizationId, page.data) }
147+
},
148+
{ isolationLevel: 'repeatable read', accessMode: 'read only' }
137149
)
138-
.orderBy(...keysetOrderBy(PEOPLE_KEYS, 'asc'))
139-
.limit(PAGE_SIZE + 1)
140-
const page = keysetPage(PEOPLE_KEYS, rows, PAGE_SIZE)
141-
return { ...page, data: await withManagers(db, organizationId, page.data) }
142150
}
143151

144152
/** The departments active people belong to, largest first. */

0 commit comments

Comments
 (0)