2
class Post < ActiveRecord::Base
    include PublicActivity::Model
      tracked owner: :user

I'm using the PublicActivity gem to track the "update" action on the Post model. The problem is that if a user clicks on "Update post" 3 times in a minute I get 3 activities for the same "updated post". Is there a way to save an activity only in a range of X-minutes? To prevent flooding.

EDIT:

Maybe a scheduled job to clean up duplicated data?

4

2 回答 2

1
activity = PublicActivity::Activity.where(trackable_id: post.id, owner_id: current_user.id).last
if activity?
  period = Time.zone.now - activity.created_at
  if period > 60              # or any time sec
    @post.create_activity     # your activity creation
  end
else
  @post.create_activity       # your activity creation
end
于 2015-10-17T11:53:35.577 回答
0

我认为您需要尝试禁用跟踪选项。更多信息在这里

于 2015-05-17T00:15:20.370 回答