get regular trust level going, self heal inconsistent topic timings

This commit is contained in:
Sam
2013-04-05 15:29:46 +11:00
parent 6aaa0ffe5e
commit 4fbf017272
14 changed files with 236 additions and 9 deletions

View File

@@ -152,6 +152,14 @@ class SiteSetting < ActiveRecord::Base
setting(:basic_requires_read_posts, 50)
setting(:basic_requires_time_spent_mins, 15)
setting(:regular_requires_topics_entered, 3)
setting(:regular_requires_read_posts, 100)
setting(:regular_requires_time_spent_mins, 60)
setting(:regular_requires_days_visited, 15)
setting(:regular_requires_likes_received, 1)
setting(:regular_requires_likes_given, 1)
setting(:regular_requires_topic_reply_count, 3)
# Entropy checks
setting(:title_min_entropy, 10)
setting(:body_min_entropy, 7)

View File

@@ -171,4 +171,24 @@ class TopicUser < ActiveRecord::Base
end
def self.ensure_consistency!
exec_sql <<SQL
UPDATE topic_users t
SET
last_read_post_number = last_read,
seen_post_count = post_count
FROM (
SELECT topic_id, user_id, COUNT(*) post_count, MAX(post_number) last_read
FROM post_timings
GROUP BY topic_id, user_id
) as X
WHERE X.topic_id = t.topic_id AND
X.user_id = t.user_id AND
(
last_read_post_number <> last_read OR
seen_post_count <> post_count
)
SQL
end
end

View File

@@ -201,6 +201,15 @@ JOIN users pu on pu.id = COALESCE(p.user_id, t.user_id)
action.created_at = hash[:created_at]
end
action.save!
action_type = hash[:action_type]
user_id = hash[:user_id]
if action_type == LIKE
User.update_all('likes_given = likes_given + 1', id: user_id)
elsif action_type == WAS_LIKED
User.update_all('likes_received = likes_received + 1', id: user_id)
end
rescue ActiveRecord::RecordNotUnique
# can happen, don't care already logged
raise ActiveRecord::Rollback
@@ -214,6 +223,14 @@ JOIN users pu on pu.id = COALESCE(p.user_id, t.user_id)
action.destroy
MessageBus.publish("/user/#{hash[:user_id]}", {user_action_id: action.id, remove: true})
end
action_type = hash[:action_type]
user_id = hash[:user_id]
if action_type == LIKE
User.update_all('likes_given = likes_given - 1', id: user_id)
elsif action_type == WAS_LIKED
User.update_all('likes_received = likes_received - 1', id: user_id)
end
end
protected