Skip to content

Commit bf55c41

Browse files
committed
Upsert game servers in sequentially to ease the load on the database
1 parent 673f30d commit bf55c41

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

apps/worker/src/workers/pollMasterServer.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ async function processor(job: Job) {
5252
if (receivedPackets !== undefined) {
5353
const masterServerInfo = unpackMasterPackets(receivedPackets.packets)
5454

55-
const ids = await Promise.all(
56-
masterServerInfo.gameServers.map(({ ip, port }) =>
57-
prisma.gameServer.upsert({
58-
where: {
59-
ip_port: {
60-
ip,
61-
port,
62-
},
63-
},
64-
select: {
65-
id: true,
66-
},
67-
update: {},
68-
create: {
55+
const ids = [];
56+
for (const { ip, port } of masterServerInfo.gameServers) {
57+
const result = await prisma.gameServer.upsert({
58+
where: {
59+
ip_port: {
6960
ip,
7061
port,
7162
},
72-
})
73-
)
74-
);
63+
},
64+
select: {
65+
id: true,
66+
},
67+
update: {},
68+
create: {
69+
ip,
70+
port,
71+
},
72+
});
73+
ids.push(result);
74+
}
7575

7676
await prisma.masterServer.update({
7777
where: {

0 commit comments

Comments
 (0)