How to load massive amount of data from Firebase Realtime Database - swift

I have a pretty big problem.
I have two databases currently in my app. It's a meeting app. I am using MongoDB to store basic user data i.e. his name, surname, email and so on. And on Firebase Realtime Database I am storing the incomingRequests, sentRequests and friendsList.
So the question is following: How can I load massive amounts of data so that I can retrieve the userIds and statuses of the user from Firebase without doing it every time I open the app.
Currently, every time I open my app, I make a request to firebase to get me all of the user Ids that I have as friends. Then I query each userId and post a request to my MongoDB with the userId so that I can get user profile picture and username. I need to fix this because my loading times are 15+ seconds if someone has 100 friends for example.
So in summary, how can I solve this big data problem??

Related

Database design for storing users log data in mongodb on daily, weekly basis

I am making a live tracking application which tracks the data of the application and the websites using by the user and stores the activity data of the user in the mongodb database. It stores the data of the user like which application or website is being used by the user and how much time they have used that application in their computer.
My current database document looks like this.
Database image
I want to store the logs of the user according to the Daily, Weekly and Monthly basis in mongodb. I want to have the database architecture to use for storing these logs on daily or weekly basis according to the user. I want to know how can I do this.

How to Implement "Your contact just joined app" feature

I am building a mobile app (in flutter firebase, but the answer does not have to be firebase specific). And I would like to implement a feature that notifies users whenever anyone from their contact list joins the app. This seems like a very EXPENSIVE feature.
At the top of my head, I see a lambda/cloud function that is triggered everytime a user joins and then searches a database of users and their respective contacts for the existence of the new user's phone number. To me, this solution does not scale well for two reasons: if the number of total users is in the millions and the number of users joining simultaneously is a lot.
My better solution is to get the user's contacts upon joining and then searching a database of current users contacts for any of the phone numbers of the newly joined user.
Is there a solution better than the second one? If so, what is it? If the second solution is standard, what kind of backend storage mechanism provides the best search and retrieval time for a database of users and their respective contacts?
In the case of large users ill not do first solution because that may slow the sign up process instead i will creat a cron job that runs at a specific time or periodically it will get the list of the latest users signed up that day or that hour whatever you prefer then that cron will check the new user if related to any user in the databases and send a notification right away, or a better solution create a temporary table in a database in another server insert the notification informations into the other server, creat another cron job in the second server it will run at a specific time to sendthe notification

check weather the user readed data or not in flutter using firestore

I was developing the chat app in flutter using firestore, the users successfully chat one-to-one. but I also want to send the notification to the user that someone sends him/her a message. For that I decided to use the cloud messaging service of firebase, but how can I check that the user read the message or not.
There is nothing built into Cloud Firestore to track which user has read a specific document already.
The two most common approaches that I know of are:
To track for each individual message and each individual user whether they have read it, so by keeping a list of the user IDs in each message document. While this potentially stores a lot of extra data, it is the most direct mapping of your use-case.
In most chat apps though, tracking of what messages each user has read is done as an "up to here". So if the user has read all messages up until a certain one or a certain time, the assumption is that they've also read all the messages before that one/moment.
For this model you can instead just keep a single document ID or timestamp for each user (i.e. readUpTo), instead of having to mark each message for each user that has read it. In your UI, you then determine whether to show each message as unread based on the message ID/timestamp compared to the timestamp of readUpTo.

Where should I keep data to continuously use in server?

Currently, I'm trying to build a dating app(server part).
I'm going to store each user's profile data like videos, photos, profile messages to AWS S3.
And I have user info including location(longitude, latitude) in my database server.
If you've ever used this kind of app, you might easily understand how it works.
First, whenever a user opens this app, the user gets to see the profile of other users one at a time based on the current location.
Second, the user gives like or dislike to the current profile and gets to the next profile.
So, in order to implement the first step, I'm going to search other users in a certain distance from the user's current location in the database, but here I'm only going to get unique user ID values from database. This only happens once when a user opens the app.
Now that I have other users' id values like [id1, id2, id3, id4...] I can load each user's profile data from AWS S3 with each unique id value one by one whenever the user needs to see the next profile.
Here my question comes. To build the recommendation logic like that, where should I keep the id values??
Thanks in advance.
Use a in memory cache like Redis/memcache (both provided by AWS). Also your cahce should get updated as and when data in AWS S3 profile updates because only then you will have latest data.

Firestore chat private and group

I have this chat structure for groups and private in real time, is there any way to structure to get the images and names of the people who chat? currently using UserIds I do a separate query to get it, but if someone changes their name or image it won't update.
You typically would start a RTDB listener for the nodes of the RTDB that contain the information for each of the users. Alternatively, you could copy all of the relevant user information into "current chats" and if a user changes their profile information you could also copy that new information into any "current chat" sessions.
In my app, I maintain user profile information in a profile collection in Firestore, and maintain the chat details in RTDB. So I have a realtime listener for the chat (RTDB) and a realtime listener for firestore.collection('profile').where('uid', 'in', arrayOfUserIDsInChat).
(Currently the way I have things, I am limited to the number of user profiles I can listen to ... in is limited to 10 ... but that is sufficient for my current requirements)