Skip to content

Commit 079a1e8

Browse files
committed
optimize the db query and check
1 parent fe15e3e commit 079a1e8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

services/apps/script_executor_worker/src/workflows/syncMembers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as activities from '../activities/sync/member'
66
import { ISyncMembersArgs } from '../types'
77

88
const activity = proxyActivities<typeof activities>({
9-
startToCloseTimeout: '30 minute',
9+
startToCloseTimeout: '45 minutes',
1010
retry: { maximumAttempts: 3, backoffCoefficient: 3 },
1111
})
1212

services/libs/opensearch/src/repo/member.repo.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,23 @@ export class MemberRepository extends RepositoryBase<MemberRepository> {
4242
}
4343

4444
public async getMembersForSync(perPage: number): Promise<string[]> {
45-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4645
const results = await this.db().any(
4746
`
48-
select m.id
49-
from members m
50-
left join indexed_entities ie on m.id = ie.entity_id and ie.type = $(type)
51-
where ie.entity_id is null
52-
limit ${perPage};`,
47+
SELECT m.id
48+
FROM members m
49+
WHERE NOT EXISTS (
50+
SELECT 1
51+
FROM indexed_entities ie
52+
WHERE ie.entity_id = m.id
53+
AND ie.type = $(type)
54+
)
55+
ORDER BY m.id
56+
LIMIT ${perPage};
57+
`,
5358
{
5459
type: IndexedEntityType.MEMBER,
5560
},
5661
)
57-
5862
return results.map((r) => r.id)
5963
}
6064

0 commit comments

Comments
 (0)