Skip to content

Commit

Permalink
check how having filter performs
Browse files Browse the repository at this point in the history
  • Loading branch information
skwowet committed Jul 23, 2024
1 parent 438bb4b commit c4ef4ed
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/src/database/repositories/memberRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,8 @@ class MemberRepository {
{ pgPromiseFormat: true },
)

options.log.info(`Member filter: ${filterString}`)

const order = (function prepareOrderBy(
orderBy = withAggregates ? 'activityCount_DESC' : 'id_DESC',
) {
Expand All @@ -2294,16 +2296,27 @@ class MemberRepository {
let searchCTE = ''
let searchJoin = ''

// check if we have a filter for identities flag
const identitiesFilter = filter.and?.find((f) => f.platforms)
const identitiesPlatforms = identitiesFilter?.platforms || []

if (withSearch) {
search = search.toLowerCase()

// search for identity platforms and if not specified, search for all
const identitiesPlatformsToSearch = identitiesPlatforms.length ? `AND platform IN ('${identitiesPlatforms.join("','")}')` : ''

// build the search where clause
const searchWhere = identitiesFilter ? `verified AND lower("value") LIKE '%${search}%' ${identitiesPlatformsToSearch}` : `(verified AND type = '${MemberIdentityType.EMAIL}' AND lower("value") LIKE '%${search}%') OR lower(m."displayName") LIKE '%${search}%'`

searchCTE = `
,
member_search AS (
SELECT
"memberId"
FROM "memberIdentities" mi
join members m on m.id = mi."memberId"
where (verified and lower("value") like '%${search}%') or lower(m."displayName") like '%${search}%'
where ${searchWhere}'
GROUP BY 1
)
`
Expand Down

0 comments on commit c4ef4ed

Please sign in to comment.