File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,22 @@ export class Query {
199
199
) ;
200
200
}
201
201
202
+ /**
203
+ * Returns true if this query does not specify any query constraints that
204
+ * could remove results.
205
+ */
206
+ matchesAllDocuments ( ) : boolean {
207
+ return (
208
+ this . filters . length === 0 &&
209
+ this . limit === null &&
210
+ this . startAt == null &&
211
+ this . endAt == null &&
212
+ ( this . explicitOrderBy . length === 0 ||
213
+ ( this . explicitOrderBy . length === 1 &&
214
+ this . getFirstOrderByField ( ) ! . isKeyField ( ) ) )
215
+ ) ;
216
+ }
217
+
202
218
// TODO(b/29183165): This is used to get a unique string from a query to, for
203
219
// example, use as a dictionary key, but the implementation is subject to
204
220
// collisions. Make it collision-free.
Original file line number Diff line number Diff line change @@ -591,4 +591,27 @@ describe('Query', () => {
591
591
orderBy ( DOCUMENT_KEY_NAME , 'asc' )
592
592
] ) ;
593
593
} ) ;
594
+
595
+ it ( 'matchesAllDocuments() considers filters, orders and bounds' , ( ) => {
596
+ const baseQuery = Query . atPath ( ResourcePath . fromString ( 'collection' ) ) ;
597
+ expect ( baseQuery . matchesAllDocuments ( ) ) . to . be . true ;
598
+
599
+ let query = baseQuery . addOrderBy ( orderBy ( '__name__' ) ) ;
600
+ expect ( query . matchesAllDocuments ( ) ) . to . be . true ;
601
+
602
+ query = baseQuery . addOrderBy ( orderBy ( 'foo' ) ) ;
603
+ expect ( query . matchesAllDocuments ( ) ) . to . be . false ;
604
+
605
+ query = baseQuery . addFilter ( filter ( 'foo' , '==' , 'bar' ) ) ;
606
+ expect ( query . matchesAllDocuments ( ) ) . to . be . false ;
607
+
608
+ query = baseQuery . withLimit ( 1 ) ;
609
+ expect ( query . matchesAllDocuments ( ) ) . to . be . false ;
610
+
611
+ query = baseQuery . withStartAt ( bound ( [ ] , true ) ) ;
612
+ expect ( query . matchesAllDocuments ( ) ) . to . be . false ;
613
+
614
+ query = baseQuery . withEndAt ( bound ( [ ] , true ) ) ;
615
+ expect ( query . matchesAllDocuments ( ) ) . to . be . false ;
616
+ } ) ;
594
617
} ) ;
You can’t perform that action at this time.
0 commit comments