iamvucms / react-native-instagram-clone

A React Native app - Clone Instagram mobile app
967 stars 318 forks source link

Leaving out the first 10 following usernames? #13

Closed moatazsoli closed 3 years ago

moatazsoli commented 3 years ago

Hi iamvucms, Great work on this project! I'm just wondering why in postActions.ts inside the FetchPostListRequest() function, you are doing a splice for the following list? This would result in leaving out the first 10 usernames that you are following and will not get any posts from them. Is this on purpose?

const rs = await firestore().collection('posts')
                        .where('userId', 'in', follwingList.splice(0, 10))
                        .orderBy('create_at', 'desc')
                        .limit(LIMIT_POSTS_PER_LOADING - collection.length)
                        .get()

Also again after getting all posts and adding the creators of those posts to the userIds array, you are doing another splice to remove the first 10 usernames from those lists.. May I ask the reason behind this? const userIds: string[] = []

while (userIds.length > 0) {
                    const rs = await firestore().collection('users')
                        .where('username', 'in', userIds.splice(0, 10))
                        .get()
                    const temp = rs.docs.map(doc => {
                        return doc.data()
                    })
                    ownInfos = ownInfos.concat(temp)
                }
iamvucms commented 3 years ago

Hi @moatazsol, I really don't understand what did I write. I didn't update it for alone time and this is the first time i work with firebase on react native. It may be a bad way to load more posts, while followingList.length still greater than 0, I will get post from 10 first user_ids who I'm following until don't have more followingId or collection.length>LIMIT

moatazsoli commented 3 years ago

ok thanks alot. I think firebase is not the best Db for those kind of queries but I think you did a great job adapting your code to it.