mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:23:13 +08:00
bug fixes for user_stat extraction, decrease querying
This commit is contained in:
parent
e18b93026a
commit
094b5eccca
|
@ -315,7 +315,7 @@ class TopicsController < ApplicationController
|
|||
end
|
||||
|
||||
def should_track_visit_to_topic?
|
||||
(!request.xhr? || params[:track_visit]) && current_user
|
||||
!!((!request.xhr? || params[:track_visit]) && current_user)
|
||||
end
|
||||
|
||||
def perform_show_response
|
||||
|
|
|
@ -11,7 +11,7 @@ class InvitedList
|
|||
@by_user = user
|
||||
|
||||
invited = Invite.where(invited_by_id: @by_user.id)
|
||||
.includes(:user)
|
||||
.includes(:user => :user_stat)
|
||||
.order(:redeemed_at)
|
||||
invited.each do |i|
|
||||
if i.redeemed?
|
||||
|
|
|
@ -8,8 +8,19 @@ class InvitedUserSerializer < BasicUserSerializer
|
|||
:days_since_created
|
||||
|
||||
def time_read
|
||||
return nil if object.time_read.blank?
|
||||
AgeWords.age_words(object.time_read)
|
||||
AgeWords.age_words(object.user_stat.time_read)
|
||||
end
|
||||
|
||||
def days_visited
|
||||
object.user_stat.days_visited
|
||||
end
|
||||
|
||||
def topics_entered
|
||||
object.user_stat.topics_entered
|
||||
end
|
||||
|
||||
def posts_read_count
|
||||
object.user_stat.posts_read_count
|
||||
end
|
||||
|
||||
def days_since_created
|
||||
|
|
|
@ -13,7 +13,7 @@ module PostStreamSerializerMixin
|
|||
return @posts if @posts.present?
|
||||
@posts = []
|
||||
@highest_number_in_posts = 0
|
||||
if object.posts.present?
|
||||
if object.posts
|
||||
object.posts.each_with_index do |p, idx|
|
||||
@highest_number_in_posts = p.post_number if p.post_number > @highest_number_in_posts
|
||||
ps = PostSerializer.new(p, scope: scope, root: false)
|
||||
|
|
|
@ -8,7 +8,7 @@ class MoveColumnsToUserStats < ActiveRecord::Migration
|
|||
add_column :user_stats, :likes_received, :integer, default: 0, null: false
|
||||
add_column :user_stats, :topic_reply_count, :integer, default: 0, null: false
|
||||
|
||||
execute 'UPDATE user_stats
|
||||
execute 'UPDATE user_stats s
|
||||
SET topics_entered = u.topics_entered,
|
||||
time_read = u.time_read,
|
||||
days_visited = u.days_visited,
|
||||
|
@ -16,8 +16,7 @@ class MoveColumnsToUserStats < ActiveRecord::Migration
|
|||
likes_given = u.likes_given,
|
||||
likes_received = u.likes_received,
|
||||
topic_reply_count = u.topic_reply_count
|
||||
FROM user_stats s
|
||||
JOIN users u on u.id = s.user_id
|
||||
FROM users u WHERE u.id = s.user_id
|
||||
'
|
||||
|
||||
remove_column :users, :topics_entered
|
||||
|
@ -38,7 +37,7 @@ class MoveColumnsToUserStats < ActiveRecord::Migration
|
|||
add_column :users, :likes_received, :integer
|
||||
add_column :users, :topic_reply_count, :integer
|
||||
|
||||
execute 'UPDATE users
|
||||
execute 'UPDATE users s
|
||||
SET topics_entered = u.topics_entered,
|
||||
time_read = u.time_read,
|
||||
days_visited = u.days_visited,
|
||||
|
@ -46,8 +45,7 @@ class MoveColumnsToUserStats < ActiveRecord::Migration
|
|||
likes_given = u.likes_given,
|
||||
likes_received = u.likes_received,
|
||||
topic_reply_count = u.topic_reply_count
|
||||
FROM users s
|
||||
JOIN user_stats u on s.id = u.user_id
|
||||
FROM user_stats u WHERE s.id = u.user_id
|
||||
'
|
||||
|
||||
remove_column :user_stats, :topics_entered
|
||||
|
|
|
@ -198,7 +198,7 @@ class TopicView
|
|||
@current_post_ids ||= if @posts.is_a?(Array)
|
||||
@posts.map {|p| p.id }
|
||||
else
|
||||
@posts.pluck(:post_number)
|
||||
@posts.pluck(:post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -214,7 +214,7 @@ class TopicView
|
|||
return result unless @user.present?
|
||||
return result unless topic_user.present?
|
||||
|
||||
post_numbers = PostTiming.select(:post_number)
|
||||
post_numbers = PostTiming
|
||||
.where(topic_id: @topic.id, user_id: @user.id)
|
||||
.where(post_number: current_post_ids)
|
||||
.pluck(:post_number)
|
||||
|
|
Loading…
Reference in New Issue
Block a user