forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/pull/4875'
- Loading branch information
Showing
6 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
db/migrate/20240605134916_add_notes_and_diary_comments_counter_caches.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class AddNotesAndDiaryCommentsCounterCaches < ActiveRecord::Migration[7.1] | ||
class DiaryComment < ApplicationRecord | ||
end | ||
|
||
class NoteComment < ApplicationRecord | ||
end | ||
|
||
class User < ApplicationRecord | ||
end | ||
|
||
def self.up | ||
add_column :users, :diary_comments_count, :integer, :default => 0 | ||
add_column :users, :note_comments_count, :integer, :default => 0 | ||
|
||
users_with_diary_comments = DiaryComment.distinct.pluck(:user_id) | ||
users_with_diary_comments.each do |user_id| | ||
User.reset_counters(user_id, :diary_comments) | ||
end | ||
|
||
users_with_note_comments = NoteComment.where.not(:author_id => nil).distinct.pluck(:author_id) | ||
users_with_note_comments.each do |author_id| | ||
User.reset_counters(author_id, :note_comments) | ||
end | ||
end | ||
|
||
def self.down | ||
remove_column :users, :diary_comments_count | ||
remove_column :users, :note_comments_count | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters