Remove relationship counters in `users` table
This commit is contained in:
parent
ce951453a2
commit
d20e07ee19
2
Rakefile
2
Rakefile
|
@ -69,8 +69,6 @@ namespace :justask do
|
||||||
asked = Question.where(user: user).where(author_is_anonymous: false).count
|
asked = Question.where(user: user).where(author_is_anonymous: false).count
|
||||||
commented = Comment.where(user: user).count
|
commented = Comment.where(user: user).count
|
||||||
smiled = Smile.where(user: user).count
|
smiled = Smile.where(user: user).count
|
||||||
user.friend_count = user.friends.count
|
|
||||||
user.follower_count = user.followers.count
|
|
||||||
user.answered_count = answered
|
user.answered_count = answered
|
||||||
user.asked_count = asked
|
user.asked_count = asked
|
||||||
user.commented_count = commented
|
user.commented_count = commented
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
class Relationships::Follow < Relationship
|
class Relationships::Follow < Relationship
|
||||||
after_create do
|
after_create do
|
||||||
Notification.notify target, self
|
Notification.notify target, self
|
||||||
# increment counts
|
|
||||||
source.increment! :friend_count
|
|
||||||
target.increment! :follower_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
Notification.denotify target, self
|
Notification.denotify target, self
|
||||||
# decrement counts
|
|
||||||
source.decrement! :friend_count
|
|
||||||
target.decrement! :follower_count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def notification_type(*_args)
|
def notification_type(*_args)
|
||||||
|
|
|
@ -76,10 +76,10 @@
|
||||||
%p.text-muted= current_user.asked_count
|
%p.text-muted= current_user.asked_count
|
||||||
|
|
||||||
%p.font-weight-bold.mb-0 Following
|
%p.font-weight-bold.mb-0 Following
|
||||||
%p.text-muted= current_user.friend_count
|
%p.text-muted= current_user.followings.count
|
||||||
|
|
||||||
%p.font-weight-bold.mb-0 Followers
|
%p.font-weight-bold.mb-0 Followers
|
||||||
%p.text-muted= current_user.follower_count
|
%p.text-muted= current_user.followers.count
|
||||||
|
|
||||||
%p.font-weight-bold.mb-0 Smiles
|
%p.font-weight-bold.mb-0 Smiles
|
||||||
%p.text-muted= current_user.smiled_count + current_user.comment_smiled_count
|
%p.text-muted= current_user.smiled_count + current_user.comment_smiled_count
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RemoveRelationshipCountersFromUsers < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
remove_column :users, :follower_count
|
||||||
|
remove_column :users, :friend_count
|
||||||
|
end
|
||||||
|
end
|
|
@ -275,8 +275,6 @@ ActiveRecord::Schema.define(version: 2022_01_05_171216) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "screen_name"
|
t.string "screen_name"
|
||||||
t.integer "friend_count", default: 0, null: false
|
|
||||||
t.integer "follower_count", default: 0, null: false
|
|
||||||
t.integer "asked_count", default: 0, null: false
|
t.integer "asked_count", default: 0, null: false
|
||||||
t.integer "answered_count", default: 0, null: false
|
t.integer "answered_count", default: 0, null: false
|
||||||
t.integer "commented_count", default: 0, null: false
|
t.integer "commented_count", default: 0, null: false
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Exporter
|
||||||
def collect_user_info
|
def collect_user_info
|
||||||
%i(answered_count asked_count ban_reason banned_until comment_smiled_count commented_count
|
%i(answered_count asked_count ban_reason banned_until comment_smiled_count commented_count
|
||||||
confirmation_sent_at confirmed_at created_at profile_header profile_header_h profile_header_w profile_header_x profile_header_y
|
confirmation_sent_at confirmed_at created_at profile_header profile_header_h profile_header_w profile_header_x profile_header_y
|
||||||
profile_picture_w profile_picture_h profile_picture_x profile_picture_y current_sign_in_at current_sign_in_ip follower_count friend_count
|
profile_picture_w profile_picture_h profile_picture_x profile_picture_y current_sign_in_at current_sign_in_ip
|
||||||
id last_sign_in_at last_sign_in_ip locale permanently_banned
|
id last_sign_in_at last_sign_in_ip locale permanently_banned
|
||||||
privacy_allow_anonymous_questions privacy_allow_public_timeline privacy_allow_stranger_answers
|
privacy_allow_anonymous_questions privacy_allow_public_timeline privacy_allow_stranger_answers
|
||||||
privacy_show_in_search profile_header_file_name profile_picture_file_name
|
privacy_show_in_search profile_header_file_name profile_picture_file_name
|
||||||
|
@ -232,8 +232,8 @@ class Exporter
|
||||||
|
|
||||||
def user_stub(user)
|
def user_stub(user)
|
||||||
uobj = {}
|
uobj = {}
|
||||||
%i(answered_count asked_count comment_smiled_count commented_count created_at follower_count
|
%i(answered_count asked_count comment_smiled_count commented_count created_at
|
||||||
friend_count id permanently_banned screen_name smiled_count).each do |f|
|
id permanently_banned screen_name smiled_count).each do |f|
|
||||||
uobj[f] = user.send f
|
uobj[f] = user.send f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue