Skip to content

Commit

Permalink
[BACKPORT] Skip callbacks on follower counters migration (decidim#4955)
Browse files Browse the repository at this point in the history
* Skip callbacks on follower counters migration

* Add changelog
  • Loading branch information
mrcasals committed Mar 11, 2019
1 parent b5e534d commit 066d830
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,28 @@

## [Unreleased](https://github.com/decidim/decidim/tree/HEAD)

### Upgrade notes

#### User follow counters
After running the migrations, please run this code from a console:

```ruby
Decidim::UserBaseEntity.find_each do |entity|
follower_count = Decidim::Follow.where(followable: entity).count
following_count = Decidim::Follow.where(decidim_user_id: entity.id).count
following_users_count = Decidim::Follow.where(decidim_user_id: entity.id, decidim_followable_type: ["Decidim::UserBaseEntity", "Decidim::User", "Decidim::UserGroup"]).count

# We use `update_columns` to skip Searchable callbacks
entity.update_columns(
followers_count: follower_count,
following_count: following_count,
following_users_count: following_users_count
)
end
```

### Changes

**Added**:

- **decidim-proposals**: Added a button to reset all participatory text drafts. [\#4817](https://github.com/decidim/decidim/pull/4817)
Expand Down Expand Up @@ -239,6 +261,7 @@ In order to generate Open Data exports you should add this to your crontab or re
- **decidim-meetings**: Filter meeting by end time instead of start time [\#4701](https://github.com/decidim/decidim/pull/4701)
- **decidim-core**: MetricResolver filtering corrected comparison between symbol and string [\#4736](https://github.com/decidim/decidim/pull/4736)
- **decidim-meetings**: Fix meeting questionnaire migration [\#4949](https://github.com/decidim/decidim/pull/4949/)
- **decidim-core**: Speed up `AddFollowingAndFollowersCountersToUsers` migration [\#4955](https://github.com/decidim/decidim/pull/4955/)

**Removed**:

Expand Down
Expand Up @@ -5,17 +5,6 @@ def up
add_column :decidim_users, :following_count, :integer, null: false, default: 0
add_column :decidim_users, :following_users_count, :integer, null: false, default: 0
add_column :decidim_users, :followers_count, :integer, null: false, default: 0

Decidim::UserBaseEntity.find_each do |entity|
follower_count = Decidim::Follow.where(followable: entity).count
following_count = Decidim::Follow.where(decidim_user_id: entity.id).count
following_users_count = Decidim::Follow.where(decidim_user_id: entity.id, decidim_followable_type: ["Decidim::UserBaseEntity", "Decidim::User", "Decidim::UserGroup"]).count

entity.followers_count = follower_count
entity.following_count = following_count
entity.following_users_count = following_users_count
entity.save
end
end

def down
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/lib/decidim/searchable.rb
Expand Up @@ -71,7 +71,7 @@ def try_update_index_for_search_resource
add_to_index_as_search_resource
else
fields = self.class.search_resource_fields_mapper.mapped(self)
searchables_in_org.each do |sr|
searchables_in_org.find_each do |sr|
sr.update(contents_to_searchable_resource_attributes(fields, sr.locale))
end
end
Expand Down

0 comments on commit 066d830

Please sign in to comment.