Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update counter_cache even not reload #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

debbbbie
Copy link

@debbbbie debbbbie commented Sep 3, 2018

ruby-china/homeland#1054

解这里的bug,内存中 target user的counter_cache没有得到刷新

@debbbbie
Copy link
Author

debbbbie commented Sep 3, 2018

@huacnlee CC

return false if action.blank?
if defined_action[:counter_cache] && action.target.present?
target_count = Action.where(
action_type: defined_action[:action_type],
target_type: action.target_type,
target_id: action.target_id
).count
action.target.update_attribute(defined_action[:counter_cache], target_count)
opts[:target].update_attribute(defined_action[:counter_cache], target_count) if opts[:target]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 target 有可能没有,有些时候传递的是 target_type 和 target_id

所以得用 action.target 稳妥些


看起来是 action_store 更新了数据,但内存中的 target 数据没变,得想其他方法来解决


抱歉,现在在看到这个 PR

Base automatically changed from master to main January 12, 2021 03:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants