Skip to content

Commit

Permalink
Pass in preferRest to initializeFirestore
Browse files Browse the repository at this point in the history
This seems to be the recommended technique: firebase/firebase-admin-node#1901 (comment)
  • Loading branch information
johnnyoshika committed Jul 7, 2023
1 parent 000ae01 commit b6f1b10
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/firebase.ts
@@ -1,5 +1,8 @@
import { initializeApp, cert } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
import {
getFirestore,
initializeFirestore,
} from 'firebase-admin/firestore';

// The service account key determines which Firebase project we're using.

Expand All @@ -12,15 +15,16 @@ const app = initializeApp(
'ltijs-firestore', // Provide a named instance so multiple apps can be initialized: https://github.com/examind-ai/ltijs-firestore/issues/3
);

const db = getFirestore(app);

db.settings({
ignoreUndefinedProperties: true,
const db = initializeFirestore(app, {
// Faster cold starts by using REST (instead of gRPC) where possible: https://github.com/firebase/firebase-admin-node/pull/1901
// As of 2023-07-06, the only operation that requires gRPC is onSnapshot(), which we don't use on the server: https://firebase.google.com/docs/reference/admin/node/firebase-admin.firestore.firestoresettings
// Cold start issue tracker: https://issuetracker.google.com/issues/158014637#comment212
// Disable `preferRest` when running with emulator b/c it causes unit tests to time out on Linux and macOS: https://github.com/firebase/firebase-admin-node/issues/2016#issuecomment-1624775019
preferRest: !process.env.FIRESTORE_EMULATOR_HOST,
});

db.settings({
ignoreUndefinedProperties: true,
});

export { db };

0 comments on commit b6f1b10

Please sign in to comment.