@@ -357,6 +357,7 @@ member_address AS (
357357)` ) ;
358358 }
359359
360+ const filterParamCount = params . length ;
360361 const pLimit = p ( limit ) ;
361362 const pOffset = p ( ( page - 1 ) * limit ) ;
362363
@@ -380,10 +381,7 @@ SELECT
380381 TRIM(COALESCE(m."firstName", '') || ' ' || COALESCE(m."lastName", '')) AS name,
381382 m."photoURL" AS "photoUrl",
382383 EXISTS (SELECT 1 FROM recently_active ra WHERE ra.user_id = m."userId") AS "isRecentlyActive",
383- (
384- COALESCE(m.verified, false) = true
385- OR EXISTS (SELECT 1 FROM verified_via_trolley vt WHERE vt.user_id = m."userId")
386- ) AS "isVerified",
384+ (COALESCE(m.verified, false) = true OR vt.user_id IS NOT NULL) AS "isVerified",
387385 COALESCE(m."availableForGigs", false) AS "openToWork",
388386 TRIM(
389387 COALESCE(maddr.city || ' ', '') ||
@@ -400,10 +398,20 @@ LEFT JOIN member_address maddr ON maddr."userId" = m."userId"
400398ORDER BY ${ orderByClause }
401399LIMIT ${ pLimit } OFFSET ${ pOffset } ` ;
402400
403- const rows = await this . db . query < RawMemberRow > ( dataQuery , params ) ;
404- const total =
405- ( page - 1 ) * limit +
406- ( rows . length === limit ? rows . length + 1 : rows . length ) ;
401+ const countQuery = `
402+ WITH ${ ctesBlock }
403+ SELECT COUNT(*)::integer AS total
404+ FROM ${ profileComplete === true ? "profile_complete_filtered pcf" : "filtered_members fm" } ` ;
405+
406+ const [ rows , countRows ] = await Promise . all ( [
407+ this . db . query < RawMemberRow > ( dataQuery , params ) ,
408+ this . db . query < { total : number } > (
409+ countQuery ,
410+ params . slice ( 0 , filterParamCount ) ,
411+ ) ,
412+ ] ) ;
413+
414+ const total = countRows [ 0 ] ?. total ?? 0 ;
407415
408416 const data : MemberResultDto [ ] = rows . map ( ( row ) => ( {
409417 id : row . id ,
0 commit comments