I'm trying to build (offline first) chat application with react native (and nodeJS, mongoDB, socketIO).
I want to ask what is the best (optimized) way to fetch friends list.
my user model structure:
mongoose.Schema({
phoneNumber: Number,
friends: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}],
})
as json
[
{
"_id": ObjectId("5e91bcd6cd1630213d95f810"),
"phoneNumber": "+995555555555",
"friends": [
ObjectId("5e57d64d92cc878760086980"),
ObjectId("5e57d64d92cc878760086981")
]
},
...
]
My current approach is I fetch friends list from api and save to localStorage when a user boot the application. So, user can see friends list even if they are offline.
And my concern is if there's 1000 users and they have 200 users in their friend list it would be expensive call.
I can only update localStorage when the user add a friend, but the user won't be able to see if a friend change their avatar or username, etc..
So, what is the best way to keep up-to-date friend list?