codeuino / social-platform-donut-backend

Donut API:
http://donut-api-prod.codeuino.org/
GNU General Public License v3.0
24 stars 57 forks source link

Implement API to showcase activities of a user to the admins #148

Open Rupeshiya opened 4 years ago

Rupeshiya commented 4 years ago

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.

  2. 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 commented 4 years ago

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

vaibhavdaren commented 4 years ago
  1. with tweaks
Rupeshiya commented 4 years ago

@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
kmehant commented 4 years ago

@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.

Rupeshiya commented 4 years ago

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.

kmehant commented 4 years ago

@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