Функции Firebase Firestore и Cloud показывают неправильное чтение, запись и удаление чисел? - PullRequest
0 голосов
/ 17 февраля 2019

У меня есть структура пожарного депо, как это:

users(collection):
    -userID_1(document):
        email: email1@gmail.com
        name: userName_1
        photo: photoUrl
        uid: userID_1
        followersNum: 1
        followingNum: 0
        questionsNum: 0
    -userID_2(document):
        email: email2@gmail.com
        name: userName_2
        photo: photoUrl
        uid: userID_2
        followersNum: 0
        followingNum: 1
        questionsNum: 0
followingFollowersPoints(collection):
    -userID_2(document):
        -following(collection):
            -userID_1(document)
                -points: 1

Мои функции Firestore и Cloud Functions, прежде чем я что-то сделал: enter image description here enter image description here Есть0 вызовов функций clud и 0 операций чтения, записи, удаления на сегодня (17 февраля) Затем я развернул свою облачную функцию с помощью firebase deploy - только функции: followUser, затем я открыл использование firestore и получил следующие числа: enter image description here Я не открывал свое приложение и не касался консоли пожарного магазина, я только что открыл страницу использования в пожарном магазине. Как это возможно?Затем я вручную обновляю два пользовательских документа и удаляю один документ в следующей коллекции перед тестированием облачной функции, поэтому я обновляю одно поле в двух документах и ​​удаляю один документ, но получаю следующие номера: Вот как изменился firestore:

As you can see I only updated two field, from value 1 to value 0 and deleted one document in following colelction
users(collection):
    -userID_1(document):
        email: email1@gmail.com
        name: userName_1
        photo: photoUrl
        uid: userID_1
        followersNum: 0
        followingNum: 0
        questionsNum: 0
    -userID_2(document):
        email: email2@gmail.com
        name: userName_2
        photo: photoUrl
        uid: userID_2
        followersNum: 0
        followingNum: 0
        questionsNum: 0
followingFollowersPoints(collection):
    -userID_2(document):
        -following(collection):

И это использование пожарного хранилища: enter image description here

Затем я вручную добавляю тот же документ в следующую коллекцию, которая вызывает облачную функцию, и моя облачная функция обновляет одно поле в двух документах.Это моя структура пожарного депо после того, как я добавил этот документ:

users(collection):
        -userID_1(document):
            email: email1@gmail.com
            name: userName_1
            photo: photoUrl
            uid: userID_1
            **followersNum: 1 -CloudFunction updated this field**
            followingNum: 0
            questionsNum: 0
        -userID_2(document):
            email: email2@gmail.com
            name: userName_2
            photo: photoUrl
            uid: userID_2
            followersNum: 0
            **followingNum: 1 -CloudFunction updated this field**
            questionsNum: 0
    followingFollowersPoints(collection):
        -userID_2(document):
            -following(collection):
                **-userID_1(document) - I added this document that invokes fucntion**
                    -points: 1

И это номера использования после вызова облачных функций: enter image description here enter image description here Тогдапросто чтобы убедиться, что числа обновлены, я обновил браузер и получил эти цифры: enter image description here Поскольку я пишу это в течение примерно 15 минут, количество операций чтения достигает 177!?!?

Я не прикасался к firestore или приложению, пока я пишу это по стеку, номера потоков растут без причины.

Это мой код CloudFunction:

admin.initializeApp();
 const db = admin.firestore();

 export const followUser = functions.firestore
    .document('followingFollowersPoints/{myUserId}/following/{followingUserId}')
    .onCreate((snap, context) => {

        const myUserId = context.params.myUserId               //update my following count
        const followingUserId = context.params.followingUserId //update his followers count
        const myUserDocRef = db.collection('users').doc(myUserId)
        const followingUserDocRef = db.collection('users').doc(followingUserId)
        return db.runTransaction(transaction => {
            return transaction.getAll(myUserDocRef, followingUserDocRef) //**********THESE ARE TWO READS*****************
                    .then(docs => {

                        const myUserData = docs[0].data()
                        const followingUserData = docs[1].data()

                        if(myUserData != null && followingUserData != null){
                            //since I am following someone - increase my followingNum
                            const newFollowingCount = myUserData.followingNum + 1
                            //then increse his followersNum
                            const newFollowersCount = followingUserData.followersNum + 1

                            //update my followingNum field in user document
                            //*******THIS IS ONE WRITE*********
                            transaction.update(myUserDocRef, {
                                followingNum : newFollowingCount
                            });
                            //*******THIS IS ONE WRITE*********
                            //update friends followersNum
                            transaction.update(followingUserDocRef, {
                                followersNum : newFollowersCount
                            });
                        }
                    });
          }).then(() => console.log('Transaction succeeded'))  
    });

Я действительно не знаюне знаю, как я могу получить эти цифры, просто это не имеет никакого смысла.У меня нет какой-либо другой облачной функции, которая может быть вызвана этими изменениями из первой облачной функции.177 операций чтения - это слишком много, когда у меня было только два чтения в облачной функции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...