sparkle
sparkle

Reputation: 7398

How do I throttle messages from PublicActivity?

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?

Upvotes: 2

Views: 78

Answers (2)

Artyom Kalmykov
Artyom Kalmykov

Reputation: 390

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

Upvotes: 1

Radek
Radek

Reputation: 202

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

Upvotes: 0

Related Questions