social-platform-donut-backend icon indicating copy to clipboard operation
social-platform-donut-backend copied to clipboard

Implement API to showcase activities of a user to the admins

Open Rupeshiya opened this issue 4 years ago • 6 comments

Is your feature request related to a problem? Please describe. As of now, there is no such API that can showcase the activities of a particular user on the platform. So the feature request is to implement the API for tracking the activities of the user which only admins can check.

Describe the solution you'd like Implement REST API for tracking user activities. We can implement this in either of the two ways listed below (from my point of view)

  1. We can make a self-object for the user and keep on adding the activity of the user on that object and save that to DB. Something like we did for the notifications system.

Pros: Easy to implement Cons: It's using extra space. So that increases the cost of the storage.

  1. We can also implement this without using any extra space as we are already saving every info of a user like, which user created what, liked which post, commented on which posts. So here in this approach, the only thing we have to do is that just iterate through all the user-related documents and deep populate to fetch those data and sort according to the date and send that in response.

Pros: Here we are not using any extra space but here it may be a little bit slower, but we can improve the speed using caching later on. Cons: Little bit complex to implement

Note: This is not realtime implementation

Rupeshiya avatar Jul 12 '20 14:07 Rupeshiya

@vaibhavdaren @devesh-verma Please add your view. Also is there any other optimal method we can use?

Rupeshiya avatar Jul 12 '20 14:07 Rupeshiya

  1. with tweaks

vaibhavdaren avatar Jul 13 '20 13:07 vaibhavdaren

@kmehant Here is the issue to start with and the given below approach we are going to use.

  1. Setup Redis server
  2. Make a middleware to track each request of a user (or should do it manually like ?)
  3. Add the activity as per the request type to the Redis-server,
  4. When the user logs out then just add that to DB and clear the Redis-server

Rupeshiya avatar Jul 13 '20 17:07 Rupeshiya

@Rupeshiya @vaibhavdaren

I am thinking of this data model for storing user activity on redis cache

A redis hash for routes 
<email> 
     <Route1> <Unique Hash 1>
     <Route2> <Unique Hash 2>
     <Route3> <Unique Hash 3>
     ....

A redis list for time stamps
<Unique Hash 1> <Timestamp 1> <Timestamps> .....

<Unique Hash 2> <Timestamp 1> <Timestamps> .....

I have adopted this model for making use of atomic operations of redis.

When pushing to mongodb, we we can simply join the routes with their timestamp lists by matching the hashes and push it to User collection.

kmehant avatar Jul 14 '20 04:07 kmehant

Great @kmehant, Also when you push the data to db then store that in a simple array of objects. In addition to that, it would be great if you send pseudo code or WIP PR.

Rupeshiya avatar Jul 14 '20 05:07 Rupeshiya

@Rupeshiya @vaibhavdaren @devesh-verma I have written a middleware #150 and description here https://github.com/codeuino/social-platform-donut-backend/pull/150#issue-448995557 Please review

kmehant avatar Jul 15 '20 08:07 kmehant