Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Duplicate activity entries #1

Closed
christospappas opened this issue Apr 12, 2011 · 4 comments
Closed

Duplicate activity entries #1

christospappas opened this issue Apr 12, 2011 · 4 comments
Assignees

Comments

@christospappas
Copy link
Owner

Add the option to check whether the same activity has recently been made, if it has then update the timestamp, otherwise create a new activity.

@speedmax
Copy link

Hello @christospappas, what is the reason that you have closed this ticket?

I think his would be a very useful feature, i know this is extremely hard to do it right with lots of lookup and potential need for multiple indexes,

Perhaps, a intelligent ID

  • produce id from md5 hash on the activity body (actor, object, receivers)
  • upsert operation on mongo driver level

this will mean if you have liked, dislike, then liked something, it would stop the dup activities

@speedmax
Copy link

Currently i have implemented a very naive way to lookup existing activity for same verb, actor, object and receiver ids, unfortunately, i am not sure how to do the deep array lookup of receivers by ids.

so here is my attempt

 ## Todo: look into more effectient lookup
receivers_array = receivers.map { |r| { :id => r.id, :type => r.class.to_s } }
existing = Activity.where('verb'=> action, 'actor.id' => self.id, 'object.id' => object.id, 'receivers' => receivers_array).first
Activity.publish(action, actor: self, object: object, receivers: receivers) unless existing

Look up within a time

existing = Activity.where('verb'=> action, 'actor.id' => self.id, 'object.id' => object.id, :'created_at'.gt => 1.hour.ago).first
Activity.publish(action, actor: self, object: object, receivers: receivers) unless existing

or please advice more efficient methods

@christospappas
Copy link
Owner Author

Hi @speedmax,

It would be good to add this feature... I closed it a while back due to not having the time to work on it further. It seems like there is a bit of interest in this gem lately so I should probably get back into maintaining it.

Your code above could work, however if you have a large number of receivers I don't think it'll perform very well. Not sure if creating a hash for all the values is a good idea either.

I'm planning on changing the gems schema so that it can scale better with sharding (@joe1chen has a fork that does this) I just haven't had time to pull and clean it up. With this schema change, it'll means activities will be duplicated for each receiver. That will make finding duplicates even more difficult.

I'll re-open and have a look at it some more when I get time. If you work out an efficient way to do it send through a pull request and i'll add you as a contributor.

@christospappas
Copy link
Owner Author

duplicate of issue #25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants