mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 19:23:36 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
22 lines
1.1 KiB
Ruby
22 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AddBookmarkCountToPosts < ActiveRecord::Migration[4.2]
|
|
def change
|
|
add_column :posts, :bookmark_count, :integer, default: 0, null: false
|
|
add_column :forum_threads, :bookmark_count, :integer, default: 0, null: false
|
|
add_column :forum_threads, :star_count, :integer, default: 0, null: false
|
|
|
|
execute "UPDATE posts SET bookmark_count = (SELECT COUNT(*)
|
|
FROM bookmarks
|
|
WHERE post_number = posts.post_number AND forum_thread_id = posts.forum_thread_id)"
|
|
|
|
execute "UPDATE forum_threads SET bookmark_count = (SELECT COUNT(*)
|
|
FROM bookmarks
|
|
WHERE forum_thread_id = forum_threads.id)"
|
|
|
|
execute "UPDATE forum_threads SET star_count = (SELECT COUNT(*)
|
|
FROM forum_thread_users
|
|
WHERE forum_thread_id = forum_threads.id AND starred = true)"
|
|
end
|
|
end
|