-
Notifications
You must be signed in to change notification settings - Fork 122
fix pagination and add filter to Organization.members #7284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,21 +148,31 @@ export class OrganizationMembers { | |
|
|
||
| async getPaginatedOrganizationMembersForOrganization( | ||
| organization: Organization, | ||
| args: { first: number | null; after: string | null }, | ||
| args: { first: number | null; after: string | null; searchTerm?: string | null }, | ||
| ) { | ||
| this.logger.debug( | ||
| 'Find paginated organization members for organization. (organizationId=%s)', | ||
| organization.id, | ||
| ); | ||
|
|
||
| const first = args.first; | ||
| const first = args.first ? Math.min(args.first, 50) : 50; | ||
| const cursor = args.after ? decodeCreatedAtAndUUIDIdBasedCursor(args.after) : null; | ||
| const searchTerm = args.searchTerm ?? ''; | ||
| const searching = searchTerm.length > 0; | ||
|
|
||
| const query = sql` | ||
| SELECT | ||
| ${organizationMemberFields(sql`"om"`)} | ||
| FROM | ||
| "organization_member" AS "om" | ||
| ${ | ||
| searching | ||
| ? sql` | ||
| JOIN "users" as "u" | ||
| ON "om"."user_id" = "u"."id" | ||
| ` | ||
| : sql`` | ||
| } | ||
| WHERE | ||
| "om"."organization_id" = ${organization.id} | ||
| ${ | ||
|
|
@@ -178,11 +188,12 @@ export class OrganizationMembers { | |
| ` | ||
| : sql`` | ||
| } | ||
| ${searching ? sql`AND to_tsvector("u"."display_name" || ' ' || "u"."email") @@ to_tsquery('simple', ${searchTerm + ':*'})` : sql``} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this happens after the pagination. So even though it isn't indexed and so it isnt very performant -- running on <= 50 elements is fine. |
||
| ORDER BY | ||
| "om"."organization_id" DESC | ||
| , "om"."created_at" DESC | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. necessary or the order doesn't match the cursor's WHERE clause. Basically, without this the last item in the array may have a cursor that is less than another element's based on: AND (
"om"."created_at" < ${cursor.createdAt}
OR (
"om"."created_at" = ${cursor.createdAt}
AND "om"."user_id" < ${cursor.id}
)
) |
||
| , "om"."user_id" DESC | ||
| , "om"."user_id" DESC | ||
| ${first ? sql`LIMIT ${first + 1}` : sql``} | ||
| LIMIT ${first + 1} | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This enforces the pagination. Whereas before it was optional. This is critical to avoid performance issues from the filter. |
||
| `; | ||
|
|
||
| const result = await this.pool.any<unknown>(query); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left out of public API until we solidify this pattern