Skip to content

Commit fe84247

Browse files
committed
BUGFIX: Batch size
1 parent 060f4d7 commit fe84247

3 files changed

Lines changed: 14 additions & 34 deletions

File tree

apps/backend/src/cron/cron.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const dailyMaintenanceJob: CronJob = {
2626

2727
const processQueuedCampaignsJob: CronJob = {
2828
name: "process-queued-campaigns",
29-
schedule: "*/10 * * * * *", // Runs every 10 seconds
29+
schedule: "* * * * * *", // Runs every second
3030
job: processQueuedCampaigns,
3131
enabled: true,
3232
}

apps/backend/src/cron/processQueuedCampaigns.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,34 @@ import { Subscriber, Prisma, SubscriberMetadata } from "../../prisma/client"
1010
import { cronJob } from "./cron.utils"
1111

1212
// TODO: Make this a config
13-
const BATCH_SIZE = 10
13+
const BATCH_SIZE = 100
1414

1515
async function getSubscribersForCampaign(
1616
campaignId: string
1717
): Promise<Map<string, Subscriber & { Metadata: SubscriberMetadata[] }>> {
18-
const lists = await prisma.campaignList.findMany({
18+
const subscribers = await prisma.subscriber.findMany({
1919
where: {
20-
campaignId,
20+
Messages: { none: { campaignId } },
21+
ListSubscribers: {
22+
some: {
23+
unsubscribedAt: null,
24+
},
25+
},
2126
},
2227
take: BATCH_SIZE,
2328
include: {
24-
List: {
25-
include: {
26-
ListSubscribers: {
27-
where: {
28-
unsubscribedAt: null,
29-
Subscriber: {
30-
Messages: { none: { campaignId } },
31-
},
32-
},
33-
include: {
34-
Subscriber: {
35-
include: {
36-
Metadata: true,
37-
},
38-
},
39-
},
40-
},
41-
},
42-
},
29+
Metadata: true,
4330
},
4431
})
4532

46-
if (!lists.length) return new Map()
33+
if (!subscribers.length) return new Map()
4734

4835
const subscribersMap = new Map<
4936
string,
5037
Subscriber & { Metadata: SubscriberMetadata[] }
5138
>()
52-
await pMap(lists, async (list) => {
53-
await pMap(list.List.ListSubscribers, (listSubscriber) => {
54-
if (listSubscriber.Subscriber) {
55-
subscribersMap.set(
56-
listSubscriber.Subscriber.id,
57-
listSubscriber.Subscriber
58-
)
59-
}
60-
})
39+
await pMap(subscribers, async (subscriber) => {
40+
subscribersMap.set(subscriber.id, subscriber)
6141
})
6242

6343
return subscribersMap

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.5.6",
2+
"version": "0.5.7",
33
"name": "letterspace",
44
"private": true,
55
"scripts": {

0 commit comments

Comments
 (0)