|
| 1 | +import { partition } from '@crowd/common' |
1 | 2 | import {
|
| 3 | + IActivityRelationsCreateData, |
2 | 4 | createOrUpdateRelations,
|
3 | 5 | getActivityRelationsSortedByTimestamp,
|
4 | 6 | } from '@crowd/data-access-layer'
|
@@ -49,23 +51,30 @@ export async function getActivitiesToCopy(latestSyncedActivityTimestamp: string,
|
49 | 51 | }
|
50 | 52 |
|
51 | 53 | export async function createRelations(activitiesRedisKey): Promise<void> {
|
52 |
| - const activities = await getActivitiyDataFromRedis(activitiesRedisKey) |
53 |
| - const promises = activities.map(async (activity) => |
54 |
| - createOrUpdateRelations(pgpQx(svc.postgres.writer.connection()), { |
55 |
| - activityId: activity.id, |
56 |
| - memberId: activity.memberId, |
57 |
| - platform: activity.platform, |
58 |
| - segmentId: activity.segmentId, |
59 |
| - username: activity.username, |
60 |
| - conversationId: activity.conversationId, |
61 |
| - objectMemberId: activity.objectMemberId, |
62 |
| - objectMemberUsername: activity.objectMemberUsername, |
63 |
| - organizationId: activity.organizationId, |
64 |
| - parentId: activity.parentId, |
65 |
| - }), |
66 |
| - ) |
| 54 | + const activities: IActivityRelationsCreateData[] = |
| 55 | + await getActivitiyDataFromRedis(activitiesRedisKey) |
| 56 | + |
| 57 | + const chunkSize = 1000 |
| 58 | + const activityChunks = partition(activities, chunkSize) |
67 | 59 |
|
68 |
| - await Promise.all(promises) |
| 60 | + for (const chunk of activityChunks) { |
| 61 | + const promises = chunk.map((activity) => |
| 62 | + createOrUpdateRelations(pgpQx(svc.postgres.writer.connection()), { |
| 63 | + activityId: activity.id, |
| 64 | + memberId: activity.memberId, |
| 65 | + platform: activity.platform, |
| 66 | + segmentId: activity.segmentId, |
| 67 | + username: activity.username, |
| 68 | + conversationId: activity.conversationId, |
| 69 | + objectMemberId: activity.objectMemberId, |
| 70 | + objectMemberUsername: activity.objectMemberUsername, |
| 71 | + organizationId: activity.organizationId, |
| 72 | + parentId: activity.parentId, |
| 73 | + }), |
| 74 | + ) |
| 75 | + |
| 76 | + await Promise.all(promises) |
| 77 | + } |
69 | 78 | }
|
70 | 79 |
|
71 | 80 | export async function saveActivityDataToRedis(key: string, activities): Promise<void> {
|
|
0 commit comments