Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Document overwriting logic, provide override? #13

Closed
archonic opened this issue Dec 21, 2019 · 3 comments
Closed

Document overwriting logic, provide override? #13

archonic opened this issue Dec 21, 2019 · 3 comments

Comments

@archonic
Copy link

archonic commented Dec 21, 2019

I've got the following in my ActivityService which writes all activites:

  def create_activity(user_id, action, resource, time = Time.now.utc)
    event = SimpleFeed::Event.new(
      {
        a: action,
        u: user_id,
        r: resource.class.name,
        rid: resource.id
      }.to_json,
      time
    )
    @activity_feeds.each { |feed| feed.store(event: event) }
  end

I've noticed that if the same user performs the same action (such as "document.edited") on the same resource, it will overwrite the previous activity. This is actually desirable - one user editing the same document 10 times would clutter the activity feed and only the most recent activity item is relevant. It'd be nice if the overwrite logic was documented on the readme. I'm wondering if there's a way to override this however. I'd like a new activity item to appear if the same user edits the same document on a different day than a previous edit.

Perhaps I should include the current 24hr period since epoch to make the events unique across days? Such as:

  def create_activity(user_id, action, resource, time = Time.now.utc)
    event = SimpleFeed::Event.new(
      {
        a: action,
        u: user_id,
        r: resource.class.name,
        rid: resource.id,
        d: (Time.now.to_i / 86400)
      }.to_json,
      time
    )
    @activity_feeds.each { |feed| feed.store(event: event) }
  end
@kigster
Copy link
Owner

kigster commented Feb 3, 2020

That’s correct. Because simple feed uses Redis Set behind the scenes you can only store an identical event once. To store each event individually you need to add the date or the day to the event itself, which is exactly what you’ve done in your example.

@archonic
Copy link
Author

archonic commented Feb 4, 2020

Ok. I may submit a PR explaining the behaviour and suggesting the "fix" here but I'll close this issue now.

@archonic archonic closed this as completed Feb 4, 2020
@kigster
Copy link
Owner

kigster commented Feb 4, 2020

That would be lovely, thanks (the PR).

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

No branches or pull requests

2 participants