remove dupes before correcting topic_ids in user action consistency check job
This commit is contained in:
parent
9c5734b773
commit
060c79ecc0
|
@ -215,6 +215,27 @@ ORDER BY p.created_at desc
|
||||||
|
|
||||||
def self.synchronize_target_topic_ids(post_ids = nil)
|
def self.synchronize_target_topic_ids(post_ids = nil)
|
||||||
|
|
||||||
|
# nuke all dupes, using magic
|
||||||
|
builder = SqlBuilder.new <<SQL
|
||||||
|
DELETE FROM user_actions USING user_actions ua2
|
||||||
|
/*where*/
|
||||||
|
SQL
|
||||||
|
|
||||||
|
builder.where <<SQL
|
||||||
|
user_actions.action_type = ua2.action_type AND
|
||||||
|
user_actions.user_id = ua2.user_id AND
|
||||||
|
user_actions.acting_user_id = ua2.acting_user_id AND
|
||||||
|
user_actions.target_post_id = ua2.target_post_id AND
|
||||||
|
user_actions.target_post_id > 0 AND
|
||||||
|
user_actions.id > ua2.id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
if post_ids
|
||||||
|
builder.where("user_actions.target_post_id in (:post_ids)", post_ids: post_ids)
|
||||||
|
end
|
||||||
|
|
||||||
|
builder.exec
|
||||||
|
|
||||||
builder = SqlBuilder.new("UPDATE user_actions
|
builder = SqlBuilder.new("UPDATE user_actions
|
||||||
SET target_topic_id = (select topic_id from posts where posts.id = target_post_id)
|
SET target_topic_id = (select topic_id from posts where posts.id = target_post_id)
|
||||||
/*where*/")
|
/*where*/")
|
||||||
|
|
|
@ -273,10 +273,16 @@ describe UserAction do
|
||||||
target_post_id: post.id,
|
target_post_id: post.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
action.reload
|
UserAction.log_action!(
|
||||||
action.target_topic_id.should == -1
|
action_type: UserAction::NEW_PRIVATE_MESSAGE,
|
||||||
|
user_id: post.user.id,
|
||||||
|
acting_user_id: post.user.id,
|
||||||
|
target_topic_id: -2,
|
||||||
|
target_post_id: post.id,
|
||||||
|
)
|
||||||
|
|
||||||
UserAction.ensure_consistency!
|
UserAction.ensure_consistency!
|
||||||
|
|
||||||
action.reload
|
action.reload
|
||||||
action.target_topic_id.should == post.topic_id
|
action.target_topic_id.should == post.topic_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue