code-corps / code-corps/code-corps-api

Add counter cache to projects for open and closed conversations

Ouverte
#1,313 2 commentaires 0 réactions 1 personne assignée Réclamée par @snewcomer Voir sur GitHub
Time: 2 hours
Langage dominant
Elixir
Étoiles
234
Forks
82
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

# Problem

When a `conversation` record is created/updated, we need to update the `open_conversations_count` and `closed _conversations_count` counter cache columns on the `projects` table.

- [ ] Add `project_id` to `Conversation`
- [ ] change in Ember app to send the project_id up to the app
- [ ] change in API
- [ ] migrate data

We'll need to update the counts based on the following logic:

- on `insert`
- `inc: [open_conversations_count: 1]`
- on `update`
- `status` "open" => "closed"
- `inc: [closed_conversations_count: 1, open_conversations_count: -1]`
- on `update`
- `status` "closed" => "open"
- `inc: [closed_conversations_count: -1, open_conversations_count: 1]`

We'll add `prepare_changes` to increment one and decrement the other. See [this example in Ecto](https://hexdocs.pm/ecto/Ecto.Changeset.html#prepare_changes/2-example)

A useful post on this, as well: https://medium.com/@kaisersly/prepare-changes-and-counter-cache-abd93b8a20a

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.