Skip to content

Commit 81c3bb6

Browse files
authored
🚑 fun facts worker loop (#274)
* ♻️ simulation upsert informations on event * ⚰️ remove dashboard endpoint * 🚑 poll funfacts worker do not loop over simulations every time
1 parent eeac0ec commit 81c3bb6

14 files changed

+223
-567
lines changed

scripts/NGC-1784-20250331.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const main = async () => {
1717
let updatedPolls = 0
1818

1919
for await (const poll of batchPolls) {
20-
await updatePollFunFacts(poll.id, { session: prisma })
20+
await updatePollFunFacts({ pollId: poll.id }, { session: prisma })
2121

2222
updatedPolls++
2323

src/adapters/redis/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const CHANNELS = {
33
}
44

55
export const KEYS = {
6+
pollsFunFactsResults: 'pollsFunFactsResults',
67
geolocationSortedIps: 'geolocationSortedIps',
78
geolocationCountries: 'geolocationCountries',
89
}

src/features/groups/groups.repository.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const createGroupAndUser = async (
7171
const [participantDto] = participants || []
7272

7373
// For now no relation
74-
const [group, simulation] = await Promise.all([
74+
const [group, simulationCreation] = await Promise.all([
7575
// create group
7676
session.group.create({
7777
data: {
@@ -111,7 +111,11 @@ export const createGroupAndUser = async (
111111
: []),
112112
])
113113

114+
const { created, simulation, updated } = simulationCreation || {}
115+
114116
return {
117+
simulationUpdated: updated,
118+
simulationCreated: created,
115119
administrator,
116120
simulation,
117121
group: {
@@ -185,7 +189,7 @@ export const createParticipantAndUser = async (
185189

186190
// For now no relation
187191
const { id: simulationId } = simulationDto
188-
const [simulation, participant] = await Promise.all([
192+
const [simulationCreation, participant] = await Promise.all([
189193
createParticipantSimulation(
190194
{
191195
userId,
@@ -217,11 +221,19 @@ export const createParticipantAndUser = async (
217221
}),
218222
])
219223

224+
const {
225+
created: simulationCreated,
226+
simulation,
227+
updated: simulationUpdated,
228+
} = simulationCreation
229+
220230
return {
221231
participant: {
222232
...participant,
223233
simulation,
224234
},
235+
simulationUpdated,
236+
simulationCreated,
225237
created: !existingParticipant,
226238
updated: !!existingParticipant,
227239
}

src/features/groups/groups.service.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,13 @@ export const createGroup = async ({
106106
groupDto: GroupCreateDto
107107
origin: string
108108
}) => {
109-
const { group, administrator, simulation } = await transaction((session) =>
110-
createGroupAndUser(groupDto, { session })
111-
)
109+
const {
110+
group,
111+
administrator,
112+
simulation,
113+
simulationUpdated,
114+
simulationCreated,
115+
} = await transaction((session) => createGroupAndUser(groupDto, { session }))
112116
const { participants } = group
113117

114118
const events = []
@@ -130,6 +134,8 @@ export const createGroup = async ({
130134
administrator,
131135
sendEmail: true,
132136
user: administrator,
137+
updated: simulationUpdated,
138+
created: simulationCreated,
133139
})
134140

135141
EventBus.emit(simulationUpsertedEvent)
@@ -180,9 +186,10 @@ export const createParticipant = async ({
180186
participantDto: ParticipantCreateDto
181187
}) => {
182188
try {
183-
const { participant, created } = await transaction((session) =>
184-
createParticipantAndUser(params, participantDto, { session })
185-
)
189+
const { participant, created, simulationCreated, simulationUpdated } =
190+
await transaction((session) =>
191+
createParticipantAndUser(params, participantDto, { session })
192+
)
186193
const {
187194
user,
188195
group,
@@ -198,6 +205,8 @@ export const createParticipant = async ({
198205
})
199206

200207
const simulationUpsertedEvent = new SimulationUpsertedEvent({
208+
created: simulationCreated,
209+
updated: simulationUpdated,
201210
sendEmail: created,
202211
administrator,
203212
simulation,

0 commit comments

Comments
 (0)