hellos3b / sjbha-bot

13 stars 17 forks source link

fit: batch/debounce posts that occur from mass syncs #185

Open varatep opened 2 years ago

varatep commented 2 years ago

When a user has multiple events that sync all at once generating multiple webhook events, the bot creates posts for every event.

hellos3b commented 2 years ago

I've thought about this before, I think to do it without wanting to jump off my balcony is to find a way to find a way to merge multiple "workouts" in one db entry

https://github.com/hellos3b/sjbha-bot/blob/48d85c123e993c5faedf1d56867446df7d28061a/bot/src/commands/fit/Workout.ts#L10-L19

Maybe I can keep the same model and just use duplicate messageId, and then join them when updating the embed. Just not a huge fan because you can't truly tell that a workout can all reference

I think a better option would be expanding the type and making a new one specifically to map post -> workouts

export type workout = {
  readonly activity_id: number;
  readonly activity_name: string;
  readonly timestamp: string;
  readonly activity_type: string;
  readonly exp: Exp.exp
}

export type workout_post = {
  readonly __version: 1;
  readonly discord_id: string;
  readonly message_id: string;
  readonly workouts: workout[];
}