How do you aggregate social activity using Postgres? - node.js

In this app I have users, posts, and groups. Users post to groups, of which many users can be a part of.
I'm trying to aggregate all this into a feed where if a multiple groups you're part of have a post made to them (in consecutive order, with no activity in between) it groups it into 1. So you'd see "Posted in 5 groups" instead of the post 5 times in your activity feed.
Example of the schema & desired result
How would you do this with Postgres queries? Imagine thousands of posts in various orders, and you only want the newsfeed to show related activities that are right next to each other
Also I'm using node js for backend if there's any libraries to do that. Thanks!

Related

Best practice to handle patch / delete in REST API

I have a collection of Employees, on which CRUD operations can be performed.
I am working on 2 given endpoints
delete multiple employees in single API requests given the ids of the employees to be deleted is given in the body of the request.
update multiple employees using single API request.
Lets consider an example where one of the ID is not found in the list of employee ids to be deleted/deleted/updated, in this case should the whole request be rejected ? or delete the existing ones and send error response only for the not found id?
It would be helpful, if you could help me with the best practice.
Thank you,
KK

GetStream Multiple Feed Instances of same group per user?

Is it possible to create multiple feeds of a feed group s.t. users can join multiple feeds of the same feed group? Specifically, we would like to create a game feed view all players in the game can see updates and post reactions/comments. Players can be part of multiple games and each game feed should be separate from any other. Is this possible using getstream and what would be the best approach?
From reading the documentation, it seems that one cannot use API to dynamically create feed groups. However, I think it should be possible to create multiple feeds of the same feed group but in their documentation (https://getstream.github.io/react-native-activity-feed/#flatfeed) it seems to suggest that we just pass the feed group and user id, which makes me think we can only create a feed per feed group per user?
Definitely, it's possible.
For example, game:game-id and users can have their own feeds too user:user-id.

How can I show list of groups with count of the group's participants with the groups in social media app?

I am working on a social media react-native app with Node JS in the backend having approx 1 million users.
I have to show a list of suggested groups to the user with the total members in the group.
Currently, I am using a count query that is taking time to calculate the total members each time.
What should I do to optimize this API or scenario?
That's a good Question. First approach is add a column in each table. 2nd approach is create a new table of count. In count table save all the counts of the app. 3rd approach is using the DB cache or backend cache.

Track multiple context for the same Bot

We have a bot that will be used by different customers and depending on their database, sector of activity we're gonna have different answers from the bot and inputs from users. Intents etc will be the same for now we don't plan to make a custom bot for each customer.
What would be the best way to separate data per customer within Chatbase?
I'm not sure if we should use
A new API key for each customer (Do we have a limitation then?)
Differentiate them by the platform filter (seems to not be appropriated)
Differentiate them by the version filter (same it would feel a bit weird to me)
Using Custom Event, not sure how though
Example, in Dialogflow we pass the customer name/id as a context parameter.
Thank you for your question. You listed the two workarounds I would suggest, I will detail the pros/cons:
New API Key for each customer: Could become unwieldy to have to change bots everytime you want to look at a different users' metrics. You should also create a general api (bot) where you send all messages in order to get the aggregate metrics. This would mean making two api calls per message.
Differentiate by version filter: This would be the preferred method, however it could lengthen load times for your reports as your number of users grows. The advantage would be that all of your metrics are in one place, and they will be aggregated while only having to send one api call per message.

Is it possible to use Instagram API in order to make a user list according to the number of followers?

Instagram API permission is strict now and I want to know whether the tool my company will make can get the permission from Instagram or not, because it may not suit with the 3 valid use case.
We are an offshore company which develops application.
One clients ( PR or Advertisement company) asked us to make an app which finds influencers(the user who has many followers) on Instagram so that the clients can ask the influencer to advertise their products.
We want to make a influencer searching tool. Lets, say if you search with #Chocolate, the list of users who have posted photos with #Chocolate will show up, and we want to sort out the list according to the number of followers.
Referring to the valid use case for Instagram, which case may be suitable for the app we want to make?
Also, by one-off project, what does it mean? We are an offshore company and get orders from a client which want us to make a tool for them. If we just make it, and will not sell or use the application again, would it be "one-off" project?
In order to avoid one-off project, do we need to keep selling or offering the app ?
There is no direct API call to make this. You have to make a series of API calls to get all the posts for hashtag, this will have user_id and name. Then for each user you have to make another API call to get followers count. And then you have sort the results and make query for >3000
For example #chocolate has 1 million posts, so to get all 1 million posts you have make about 50000 API calls (u get 20 post per API call), and then you have to make 1 million user_info API calls to get follower counts, so 1050000 API calls total and you have 5000/hr API calls limit. So to complete this operation it will take you 9 days.
This will be a one off project if u do for a client use, you have to make a platform or service for this feature and have your client (and others) login and use the service.
In any case, the project is unrealistic to implement due to the limitation of APIs

Resources