Make updating converted prices more robust #92

Open
opened 2025-03-22 16:05:19 +00:00 by lukas · 0 comments
Owner

Right now the code is quite fragile:

  1. First it's manually checked in Purchase model's save() method if the converted price or currency is different, if it is, it sets both to default.
  2. It's checked in the convert_prices method, and this uses the same way as in the save() method, which means code duplication.
  3. calculate_price_per_game also depends on this and is itself very hacky way of determining if an update is needed. It does this by directly querying Django-Q's table Tasks and comparing its last run timestamp with the updated_at field of Purchase model.

Solutions

  1. Either add a needs_price_update field to Purchase which would be reset in the model's save method. Being boolean it's unlikely to ever change, and the brittle check in convert_prices would just check the value of this field.
  2. This would also be re-used for calculate_price_per_game because if a price has changed we also need to recalculate this.
Right now the code is quite fragile: 1. First it's manually checked in Purchase model's `save()` method if the converted price or currency is different, if it is, it sets both to default. 2. It's checked in the `convert_prices` method, and this uses the same way as in the `save()` method, which means code duplication. 3. `calculate_price_per_game` also depends on this and is itself very hacky way of determining if an update is needed. It does this by directly querying Django-Q's table `Tasks` and comparing its last run timestamp with the `updated_at` field of Purchase model. # Solutions 1. Either add a `needs_price_update` field to Purchase which would be reset in the model's save method. Being boolean it's unlikely to ever change, and the brittle check in `convert_prices` would just check the value of this field. 2. This would also be re-used for `calculate_price_per_game` because if a price has changed we also need to recalculate this.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: lukas/timetracker#92
No description provided.