Skip to content

Commit 7863038

Browse files
committed
Add memoized target for aggregate queries. Backport from iOS.
1 parent 457265f commit 7863038

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/firestore/src/core/query.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class QueryImpl implements Query {
7070
// The corresponding `Target` of this `Query` instance.
7171
memoizedTarget: Target | null = null;
7272

73+
// The corresponding `Target` of this `Query` instance for use with
74+
// aggregate queries
75+
memoizedAggregateTarget: Target | null = null;
76+
7377
/**
7478
* Initializes a Query with a path and optional additional query constraints.
7579
* Path must currently be empty if this is a collection group query.
@@ -287,8 +291,15 @@ export function queryToTarget(query: Query): Target {
287291
export function queryToAggregateTarget(query: Query): Target {
288292
const queryImpl = debugCast(query, QueryImpl);
289293

290-
// Do not include implicit order-bys for aggregate queries.
291-
return _queryToTarget(queryImpl, query.explicitOrderBy);
294+
if (!queryImpl.memoizedAggregateTarget) {
295+
// Do not include implicit order-bys for aggregate queries.
296+
queryImpl.memoizedAggregateTarget = _queryToTarget(
297+
queryImpl,
298+
query.explicitOrderBy
299+
);
300+
}
301+
302+
return queryImpl.memoizedAggregateTarget;
292303
}
293304

294305
export function _queryToTarget(

0 commit comments

Comments
 (0)