Skip to content

Commit b7ce392

Browse files
committed
add activity count filtering capability, used in serp enrichment
1 parent 0cf254b commit b7ce392

File tree

3 files changed

+20
-3
lines changed
  • services
    • apps/premium/members_enrichment_worker/src
    • libs/data-access-layer/src/old/apps/premium/members_enrichment_worker

3 files changed

+20
-3
lines changed

services/apps/premium/members_enrichment_worker/src/sources/serp/service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ import { IMemberEnrichmentDataSerp, IMemberEnrichmentSerpApiResponse } from './t
1414
export default class EnrichmentServiceSerpApi extends LoggerBase implements IEnrichmentService {
1515
public source: MemberEnrichmentSource = MemberEnrichmentSource.SERP
1616
public platform = `enrichment-${this.source}`
17+
public enrichMembersWithActivityMoreThan = 10
1718

1819
public enrichableBySql = `
20+
("activitySummary".total_count > ${this.enrichMembersWithActivityMoreThan}) AND
1921
(members."displayName" like '% %') AND
2022
(members.attributes->'location'->>'default' is not null and members.attributes->'location'->>'default' <> '') AND
2123
((members.attributes->'websiteUrl'->>'default' is not null and members.attributes->'websiteUrl'->>'default' <> '') OR
2224
(mi.verified AND mi.type = 'username' and mi.platform = 'github') OR
2325
(mi.verified AND mi.type = 'email')
2426
)`
2527

26-
// bust cache after 60 days
27-
public cacheObsoleteAfterSeconds = 60 * 60 * 24 * 60
28+
// bust cache after 120 days
29+
public cacheObsoleteAfterSeconds = 60 * 60 * 24 * 120
2830

2931
constructor(public readonly log: Logger) {
3032
super(log)

services/apps/premium/members_enrichment_worker/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface IEnrichmentService {
3939
// SQL filter to get enrichable members for a source
4040
// members table is available as "members" alias
4141
// memberIdentities table is available as "mi" alias
42+
// activity count is available in "activitySummary" alias, "activitySummary".total_count field
4243
enrichableBySql: string
4344

4445
// should either return the data or null if it's a miss

services/libs/data-access-layer/src/old/apps/premium/members_enrichment_worker/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,20 @@ export async function fetchMembersForEnrichment(
4444
}
4545

4646
return db.connection().query(
47-
`SELECT
47+
`
48+
WITH "activitySummary" AS (
49+
SELECT
50+
msa."memberId",
51+
sum(msa."activityCount") AS total_count
52+
FROM "memberSegmentsAgg" msa
53+
WHERE msa."segmentId" IN (
54+
SELECT id
55+
FROM segments
56+
WHERE "grandparentId" IS NOT NULL AND "parentId" IS NOT NULL
57+
)
58+
group by msa."memberId"
59+
)
60+
SELECT
4861
members."id",
4962
members."tenantId",
5063
members."displayName",
@@ -59,6 +72,7 @@ export async function fetchMembersForEnrichment(
5972
FROM members
6073
INNER JOIN tenants ON tenants.id = members."tenantId"
6174
INNER JOIN "memberIdentities" mi ON mi."memberId" = members.id
75+
INNER JOIN "activitySummary" on "activitySummary"."memberId" = members.id
6276
WHERE
6377
${enrichableBySqlJoined}
6478
AND tenants."deletedAt" IS NULL

0 commit comments

Comments
 (0)