2017-06-22 11 views
1

友人がアドレス帳を介してお互いを見つけられるソーシャルアプリを作成しています。基本的に私は2つの長い電話番号のリストを持っており、firebase-cloud-functionを使って両方のリストに存在するすべての数字を探したいと思います。Firebaseクラウドの機能が正しくログに記録されない

これを行うには、Firebase Realtime Databaseにユーザの連絡先情報をすべて投稿し、クラウド機能が起動されます(.onWrite)。クラウド機能は、投稿されたすべての電話番号を取得し、次にデータベース内のすべての検証済み電話番号を取得し、2つのリストを相互参照してすべての一致を見つける必要があります。ここで

は私のコードは私が私の端末でfirebase functions:logを実行すると、ログが不完全である...何らかの理由で

exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => { 

    //if it already existed then this function triggered beacuse we are calling set(null) and thus we dont want to proceed 
    if (event.data.previous.exists()) { 
     console.log("PREVIOUSLY EXISTED. RETURN NULL!!!"); 
     return null; 
    } 

    const userId = event.params.userId; 
    const userContacts = event.data.val(); 

    var contactsOnPhone = []; 
    var contactsVerifiedInDatabase =[]; 
    var matchedContacts= []; 

    for (var key in userContacts){ 
     let contact = new Object(); 
     contact.contactName = userContacts[key]; 
     contact.number = key; 
     contactsOnPhone.push(contact); 
    }; 

    var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers'); 
    return verifiedNumsRef.once('value', function(snapshot) { 
     const verifiedUsers = snapshot.val(); 

     for (key in verifiedUsers){ 
      const number = key 
      const userInfo = verifiedUsers[key]; 
      for (key in userInfo){ 
       const uid = key; 
       const username = userInfo[key]; 

       var verifiedContact = new Object(); 
       verifiedContact.name = username; 
       verifiedContact.uid = uid; 
       verifiedContact.number = number; 
       contactsVerifiedInDatabase.push(verifiedContact); 
      }; 

     }; 

     var verifiedNumbers = contactsVerifiedInDatabase.map(function(x){ 
      return x.number; 
     }); 
     var contactNumbers = contactsOnPhone.map(function(x){ 
      return x.number; 
     }); 

     //THIS LINE DOES NOT EVEN GET LOGGED UNLESS I COMMENT OUT THE FOR-LOOP BELOW, ONLY THEN DOES THIS LINE GETS LOGGED 
     console.log('got ', verifiedNumbers.length, ' verified numbers along with', contactsVerifiedInDatabase.length, ' verfieid contacts. Also got', contactNumbers.length, ' phone numbers along with ', contactsOnPhone.length, ' phone contacts'); 



     for (i = 0; i < contactNumbers.length; i++){ 

      console.log("i = ", i); 

      if (verifiedNumbers.includes(contactNumbers[i])) { 
       console.log("GOT A MATCH WITH # ", contactNumbers[i]); 
      } else { 
       console.log("No mATCH FOR # ", contactNumbers[i]); 
      }; 
     }; 

     return null;   

    }); 


}); 

です。ここにログがあります... functions log

forループがループするたびにログ印刷が行われないのはなぜですか?それは、i = 0をi = 409まで印字してはならないのですか?なぜそれはいつも393で始まるのですか?また、機能はステータス「タイムアウト」で終了していますが、それはなぜですか?

+0

私はすべてをコメントアウトするだけのための '実行しようとした(I = 0; I <500; iは++){にconsole.log(I);};'まだfirebaseログのみスルー466を示します最後の33 "console.log"のみをログするたびに – MikeG

+1

このコマンドを試す 'firebase functions:log -n 500' – theblindprophet

+0

これはうまくいった!ありがとうございました。あなたはどのようにそれを読むのですか? Firebaseのマニュアルで何も見つかりませんでした – MikeG

答えて

2

firebase functions:logは、デフォルトでいくつかの行数を出力する必要があります。約40ほどそうです。

あなたはあなたを伝えるコマンドラインオプションを取得するためにfirebase help functions:logを実行することができます:

Usage: functions:log [options] 

read logs from deployed functions 

Options: 

-h, --help    output usage information 
--only <function_names> only show logs of specified, comma-seperated functions (e.g. "funcA,funcB") 
-n, --lines <num_lines> specify number of log lines to fetch 
--open     open logs page in web browser 

はそうちょうど500行を取得するには firebase functions:log -n 500を実行します。彼らは最初か最後の500、おそらく最後かどうかを指定しません。しかし、十分です。

Functions Help

関連する問題