Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix bug where deploying Firestore function resulted in redudant API calls to the Firestore API (#6583).
- Fix an issue preventing Vite applications from being emulated on Windows. (#6411)
- Addressed an issue preventing Astro applications from being deployed from Windows. (#5709)
- Fixed an issue preventing Angular apps using ng-deploy from being emulated or deployed. (#6584)
Expand Down
20 changes: 19 additions & 1 deletion src/deploy/functions/services/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@ import * as backend from "../backend";
import * as firestore from "../../../gcp/firestore";
import { FirebaseError } from "../../../error";

const dbCache = new Map<string, firestore.Database>();

/**
* A memoized version of firestore.getDatabase that avoids repeated calls to the API.
*
* @param project the project ID
* @param databaseId the database ID or "(default)"
*/
async function getDatabase(project: string, databaseId: string): Promise<firestore.Database> {
const key = `${project}/${databaseId}`;
if (dbCache.has(key)) {
return dbCache.get(key)!;
}
const db = await firestore.getDatabase(project, databaseId);
dbCache.set(key, db);
return db;
}

/**
* Sets a firestore event trigger's region to the firestore database region.
* @param endpoint the firestore endpoint
*/
export async function ensureFirestoreTriggerRegion(
endpoint: backend.Endpoint & backend.EventTriggered
): Promise<void> {
const db = await firestore.getDatabase(
const db = await getDatabase(
endpoint.project,
endpoint.eventTrigger.eventFilters?.database || "(default)"
);
Expand Down
2 changes: 1 addition & 1 deletion src/gcp/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const apiClient = new Client({
urlPrefix: firestoreOrigin,
});

interface Database {
export interface Database {
name: string;
uid: string;
createTime: string;
Expand Down