-
Notifications
You must be signed in to change notification settings - Fork 734
member aggs sync improvements #2779
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4b28873
rm tenant logic in search-sync scripts and logic
skwowet 25fa2fc
move member sync script to script-executor-worker
skwowet 0f77c45
rm memberIds support in workflow
skwowet 7bde72e
fix
skwowet e50d1cc
change startToCloseTimeout
skwowet 5ecfca9
change startToCloseTimeout
skwowet 0fd156a
run prettier
skwowet b12c575
add dedup improvement
skwowet 6398d7f
fix ci cd
skwowet fb30296
fix workflow timeout
skwowet 0b2795a
change default batchSize
skwowet 537d325
check if parallel processing works
skwowet 4e45aa9
increase chunk size
skwowet 6917563
parallel syncing
skwowet 9b39513
customize chunkSize
skwowet 5a2cdd7
improve
skwowet a9031af
fix speed calculation
skwowet 053ce54
fix calc
skwowet 086a2d3
Merge branch 'main' into fix/CM-1999
skwowet 968f8e6
Merge branch 'main' into fix/CM-1999
skwowet dfd7bc2
fix linter
skwowet 4cc5d80
Merge branch 'main' into fix/CM-1999
skwowet 9acb673
rm tenantId column from indexedEntities
skwowet ed55301
Merge branch 'main' into fix/CM-1999
skwowet 08d2b65
Merge branch 'main' into fix/CM-1999
skwowet be017ec
use pg reader instance for getMembersForSync
skwowet f96f5c6
use continueAsNew instead of looping
skwowet 927bc33
rm index
skwowet fe15e3e
Merge branch 'main' into fix/CM-1999
skwowet 079a1e8
optimize the db query and check
skwowet 1151b8d
Add index
skwowet 70589ec
rename migration
skwowet ca35595
Merge branch 'main' into fix/CM-1999
skwowet fe9e34b
Merge branch 'main' into fix/CM-1999
skwowet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
backend/src/database/migrations/V1738589807__rmTenantIdinIndexedEntities.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| alter table indexed_entities drop column tenant_id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
services/apps/script_executor_worker/src/activities/sync/member.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { sumBy } from '@crowd/common' | ||
| import { DbStore } from '@crowd/data-access-layer/src/database' | ||
| import { MemberSyncService } from '@crowd/opensearch' | ||
| import { IndexedEntityType } from '@crowd/opensearch/src/repo/indexing.data' | ||
| import { IndexingRepository } from '@crowd/opensearch/src/repo/indexing.repo' | ||
| import { MemberRepository } from '@crowd/opensearch/src/repo/member.repo' | ||
|
|
||
| import { svc } from '../../main' | ||
|
|
||
| export async function deleteIndexedEntities(entityType: IndexedEntityType): Promise<void> { | ||
| const indexingRepo = new IndexingRepository(svc.postgres.writer, svc.log) | ||
| await indexingRepo.deleteIndexedEntities(entityType) | ||
| } | ||
|
|
||
| export async function markEntitiesIndexed( | ||
| entityType: IndexedEntityType, | ||
| entityIds: string[], | ||
| ): Promise<void> { | ||
| const indexingRepo = new IndexingRepository(svc.postgres.writer, svc.log) | ||
| await indexingRepo.markEntitiesIndexed(entityType, entityIds) | ||
| } | ||
|
|
||
| export async function getMembersForSync(batchSize: number): Promise<string[]> { | ||
| const memberRepo = new MemberRepository(svc.redis, svc.postgres.reader, svc.log) | ||
| return memberRepo.getMembersForSync(batchSize) | ||
| } | ||
|
|
||
| export async function syncMembersBatch( | ||
| memberIds: string[], | ||
| withAggs: boolean, | ||
| chunkSize?: number, | ||
| ): Promise<{ docCount: number; memberCount: number }> { | ||
| try { | ||
| const service = new MemberSyncService( | ||
| svc.redis, | ||
| svc.postgres.writer, | ||
| new DbStore(svc.log, svc.questdbSQL), | ||
| svc.opensearch, | ||
| svc.log, | ||
| ) | ||
|
|
||
| const CHUNK_SIZE = chunkSize || 10 | ||
|
|
||
| svc.log.info(`Syncing members in chunks of ${CHUNK_SIZE} members!`) | ||
|
|
||
| const results = [] | ||
| for (let i = 0; i < memberIds.length; i += CHUNK_SIZE) { | ||
| const chunk = memberIds.slice(i, i + CHUNK_SIZE) | ||
| const chunkResults = await Promise.all( | ||
| chunk.map((memberId) => service.syncMembers(memberId, { withAggs })), | ||
| ) | ||
| results.push(...chunkResults) | ||
| } | ||
|
|
||
| return { | ||
| docCount: sumBy(results, (r) => r.documentsIndexed), | ||
| memberCount: sumBy(results, (r) => r.membersSynced), | ||
| } | ||
| } catch (err) { | ||
| throw new Error(err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
services/apps/script_executor_worker/src/workflows/syncMembers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { proxyActivities } from '@temporalio/workflow' | ||
|
|
||
| import { IndexedEntityType } from '@crowd/opensearch/src/repo/indexing.data' | ||
|
|
||
| import * as activities from '../activities/sync/member' | ||
| import { ISyncMembersArgs } from '../types' | ||
|
|
||
| const activity = proxyActivities<typeof activities>({ | ||
| startToCloseTimeout: '30 minute', | ||
| retry: { maximumAttempts: 3, backoffCoefficient: 3 }, | ||
| }) | ||
|
|
||
| export async function syncMembers(args: ISyncMembersArgs): Promise<void> { | ||
| const BATCH_SIZE = args.batchSize || 100 | ||
| const WITH_AGGS = args.withAggs || true | ||
|
|
||
| console.log(`Starting members sync! (batchSize: ${BATCH_SIZE}, withAggs: ${WITH_AGGS})`) | ||
|
|
||
| if (args.clean) { | ||
| await activity.deleteIndexedEntities(IndexedEntityType.MEMBER) | ||
| console.log('Deleted indexed entities for members!') | ||
| } | ||
|
|
||
| let totalMembersSynced = 0 | ||
| let totalDocumentsIndexed = 0 | ||
|
|
||
| let memberIds = await activity.getMembersForSync(BATCH_SIZE) | ||
|
|
||
| while (memberIds.length > 0) { | ||
| const batchStartTime = new Date() | ||
| const { docCount, memberCount } = await activity.syncMembersBatch( | ||
| memberIds, | ||
| WITH_AGGS, | ||
| args.chunkSize, | ||
| ) | ||
|
|
||
| totalMembersSynced += memberCount | ||
| totalDocumentsIndexed += docCount | ||
|
|
||
| const diffInSeconds = (new Date().getTime() - batchStartTime.getTime()) / 1000 | ||
|
|
||
| console.log( | ||
| `Synced ${memberCount} members! Speed: ${Math.round( | ||
| memberCount / diffInSeconds, | ||
| )} members/second!`, | ||
| ) | ||
|
|
||
| await activity.markEntitiesIndexed(IndexedEntityType.MEMBER, memberIds) | ||
|
|
||
| if (args.testRun) { | ||
| console.log('Test run completed - stopping after first batch!') | ||
| break | ||
| } | ||
|
|
||
| memberIds = await activity.getMembersForSync(BATCH_SIZE) | ||
| } | ||
|
|
||
| console.log( | ||
| `Synced total of ${totalMembersSynced} members with ${totalDocumentsIndexed} documents!`, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.