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

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

Open
Rupeshiya opened this issue Jul 12, 2020 · 6 comments · May be fixed by #150
Open

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

Rupeshiya opened this issue Jul 12, 2020 · 6 comments · May be fixed by #150
Labels

Comments

@Rupeshiya
Copy link
Member

Rupeshiya commented Jul 12, 2020

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
Copy link
Member Author

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

@vaibhavdaren
Copy link
Member

  1. with tweaks

@Rupeshiya
Copy link
Member Author

@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
Copy link
Contributor

kmehant commented Jul 14, 2020

@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
Copy link
Member Author

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
Copy link
Contributor

kmehant commented Jul 15, 2020

@Rupeshiya @vaibhavdaren @devesh-verma
I have written a middleware #150 and description here #150 (comment)
Please review

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

Successfully merging a pull request may close this issue.

3 participants