Skip to content

Commit 574f530

Browse files
committed
Optimize global counts update worker with pagination and ordering
- Add `orderBy` and `take` options to limit and order records in global counts update functions - Ensure consistent processing of records by sorting by creation time - Limit batch size to 1000 records per update to improve performance and memory usage
1 parent 19e13a5 commit 574f530

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

apps/worker/src/workers/updateGlobalCounts.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export async function updatePlayersCount(lastUpdateDate: Date) {
2727
gt: lastUpdateDate,
2828
},
2929
},
30+
orderBy: {
31+
createdAt: 'asc',
32+
},
33+
take: 1000,
3034
});
3135

3236
console.log(`Found ${players.length} players to update (${lastUpdateDate.toISOString()} - ${new Date().toISOString()})`);
@@ -47,6 +51,10 @@ export async function updateClansCount(lastUpdateDate: Date) {
4751
gt: lastUpdateDate,
4852
},
4953
},
54+
orderBy: {
55+
createdAt: 'asc',
56+
},
57+
take: 1000,
5058
});
5159

5260
if (clans.length > 0) {
@@ -65,6 +73,10 @@ export async function updateGameServersCount(lastUpdateDate: Date) {
6573
gt: lastUpdateDate,
6674
},
6775
},
76+
orderBy: {
77+
createdAt: 'asc',
78+
},
79+
take: 1000,
6880
});
6981

7082
if (gameServers.length > 0) {
@@ -83,6 +95,10 @@ export async function updateMapsCount(lastUpdateDate: Date) {
8395
gt: lastUpdateDate,
8496
},
8597
},
98+
orderBy: {
99+
createdAt: 'asc',
100+
},
101+
take: 1000,
86102
});
87103

88104
if (maps.length > 0) {
@@ -101,6 +117,10 @@ export async function updateGameTypesCount(lastUpdateDate: Date) {
101117
gt: lastUpdateDate,
102118
},
103119
},
120+
orderBy: {
121+
createdAt: 'asc',
122+
},
123+
take: 1000,
104124
});
105125

106126
if (gameTypes.length > 0) {

0 commit comments

Comments
 (0)