Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks
joshsmith opened this issue Dec 20, 2017 · 2 comments
Open
4 tasks

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

joshsmith opened this issue Dec 20, 2017 · 2 comments
Assignees

Comments

@joshsmith
Copy link
Contributor

joshsmith commented Dec 20, 2017

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

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

@joshsmith joshsmith added this to the ✉️ Messages milestone Dec 20, 2017
@joshsmith joshsmith changed the title Add counter cache to projects for open conversations Add counter cache to projects for open and closed conversations Dec 23, 2017
@joshsmith joshsmith removed the blocked label Dec 23, 2017
@snewcomer snewcomer self-assigned this Dec 26, 2017
@snewcomer
Copy link
Contributor

tackling this

@snewcomer
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants