node.js - ESOCKETTIMEDOUT Cloud Functions for Firebase -
i using cloud functions firebase firebase realtime database in order data management app.
one of functions though seems terminated since takes 100-150 seconds complete. happens error : esockettimedout
.
is there way prevent this?
here function:
function gettopcarsforuserwithpreferences(userid, genres) { const pathtocars = admin.database().ref('cars'); pathtocars.orderbychild("istop").equalto(true).once("value").then(function(snapshot) { return writesuggestedcars(userid, genres, snapshot); }).catch(reason => { console.log(reason) }) } function writesuggestedcars(userid, genres, snapshot) { const carstowrite = {}; var snapcount = 0 snapshot.foreach(function(carsnapshot) { snapcount += 1 const cardict = carsnapshot.val(); const cargenres = cardict.tacargenre; const genre_one = genres[0]; const genre_two = genres[1]; if (cargenres[genre_one] === true ||cargenres[genre_two] == true) { carstowrite[carsnapshot.key] = cardict } if (snapshot.numchildren() - 1 == snapcount) { const pathtosuggest = admin.database().ref('carssuggested').child(userid); pathtosuggest.set(carstowrite).then(snap => { }).catch(reason => { console.log(reason) }); } }); }
the gettopcarsforuserwithpreferences
gets called when user adds preferences. cars
table has 50k entries.
well need return everytime use async task.
edit: return 'writesuggestedcars' think never returns value. not have compiler, thought return promise.resolved(). can insert putted 'here'?
maybe work:
function gettopcarsforuserwithpreferences(userid, genres) { const pathtocars = admin.database().ref('cars'); return pathtocars.orderbychild("istop").equalto(true).once("value").then(function(snapshot) { return writesuggestedcars(userid, genres, snapshot); }).catch(reason => { console.log(reason) }) } function writesuggestedcars(userid, genres, snapshot) { const carstowrite = {}; var snapcount = 0 snapshot.foreach(function(carsnapshot) { snapcount += 1 const cardict = carsnapshot.val(); const cargenres = cardict.tacargenre; const genre_one = genres[0]; const genre_two = genres[1]; if (cargenres[genre_one] === true ||cargenres[genre_two] == true) { carstowrite[carsnapshot.key] = cardict } if (snapshot.numchildren() - 1 == snapcount) { const pathtosuggest = admin.database().ref('carssuggested').child(userid); return pathtosuggest.set(carstowrite).then(snap => { // 'here' think return promise/promise.resolve() work }).catch(reason => { console.log(reason) }); } }); }
Comments
Post a Comment