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?

sparkle
  • 7,530
  • 22
  • 69
  • 131

2 Answers2

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
Artyom Kalmykov
  • 390
  • 1
  • 9
0

I think you need to experiment with disable tracking option. More info here

Radek
  • 202
  • 2
  • 6