code-corps / code-corps-api

Elixir/Phoenix API for Code Corps.
https://www.codecorps.org
MIT License
234 stars 86 forks source link

Add counter cache to projects for open and closed conversations #1313

Open joshsmith opened 6 years ago

joshsmith commented 6 years ago

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.

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

We'll add prepare_changes to increment one and decrement the other. See this example in Ecto

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

snewcomer commented 6 years ago

tackling this

snewcomer commented 6 years ago

@joshsmith Do you think the Conversation needs an explicit association to a project for this to work? I think it will if we need to cast the project_id.