1

I can track user activity on posts, so that users can see for example "2 updates!". The essence of the strategy I’m using leverages 2 tables:


post_activity: post_id | user_id | time_created

post_users: post_id | user_id | time_created | time_last_seen


With these 2 tables, I can query all records from post_activity where the post_user.time_last_seen is less than the post_activity.time_created for a count of all new items.

The problem is that post_activity is essentially an anonymous log, with no associated rows or notion of the type of action that caused it. What I can’t solve is for example this scenario:

  • User A creates new post (1 new activity stored)
  • User B comments on new post (1 new activity stored)
  • User C sees "2 new!" but...
  • User A or B deletes their contribution.

As far as the system is concerned, there are 2 unseen items but the user may see nothing!

Can anyone provide a simple demonstration of how I might have a stronger relationship between activity and user actions here? Particularly one that supports unseen deleted activity?

2
  • copy on write to post_activity_history table Commented Mar 24, 2016 at 20:13
  • Is Your story in chronological order?
    – Jasen
    Commented Jun 11, 2022 at 0:32

1 Answer 1

0

Create a TRIGGER on the table in which deletes are recorded and update related tables as required.

Relevant postgresql documentation

1
  • I think triggers could be a good fit here, but what I’m still unclear on is how to target the right record in the activity table—I can’t just remove the most recent, because other activity may be generated before someone deletes an unseen post.
    – jlmakes
    Commented Mar 24, 2016 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.