async function handle (path, uid, companyName) {
console.time('handle')
console.time('search')
const result = await searchByCompanyName(companyName, 5)
console.timeEnd('search')
console.time('write')
return firestoreDb.writeBatch(path, result)
.then(() => {
console.timeEnd('write')
return console.timeEnd('handle')
})
}
function writeBatch (path, arr, idRef = 'id') {
const batch = db().batch()
const ref = db().collection(path)
console.log(`batching ${arr.length} results`)
return Promise.all(
[
arr.map(async item => {
let itemRef = ref.doc(item[idRef])
return batch.set(itemRef, item)
})
]
).then(() => {
return batch.commit()
})
}
function writeBatch (path, arr, idRef = 'id') {
const batch = db().batch()
const ref = db().collection(path)
console.log(`batching ${arr.length} results`)
arr.forEach(item => {
let itemRef = ref.doc(item[idRef])
batch.set(itemRef, item)
})
return batch.commit()
}

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/20ab3b44-ab3f-4adb-8431-2cce4311a662%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
let _db = null
/**
* Initialises the DB handle if it hasn't yet.
*
* PS remember this for date handling:
*
* // Old:
* const date = snapshot.get('created_at');
* // New:
* const timestamp = snapshot.get('created_at');
* const date = timestamp.toDate();
*
* @returns {*}
*/
const db = () => {
if (_db === null) {
const settings = {timestampsInSnapshots: true}
_db = admin.firestore()
// gets rid of
// "The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK."
_db.settings(settings)
}
return _db
}
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/CAE6e%2BPhytzC87PhXhaXU4O0ggQK0zYAhFjYQ%3DrNSUVDxmA4S0Q%40mail.gmail.com.
const handle = async (uid, data) => {
const companyNumber = data.number
console.time('read')
const teamProfile = await firestoreDb.read(`team/${companyNumber}`)
console.timeEnd('read')
const data2 = _.assign({}, data, {
random: Math.random().toString(36).substring(7)
})
console.time('write')
return firestoreDb.write('junk/' + uid, data2).then(() => {
return console.timeEnd('write')
})
}

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8d5c7cdb-63c8-4ffd-8633-06f59aaa288f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/f1053fba-68ce-4b5e-9d9a-105c7719fb33%40googlegroups.com.