File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
src/firebase/firestore/core
test/firebase/firestore/core Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ bool Query::IsDocumentQuery() const {
57
57
filters_.empty ();
58
58
}
59
59
60
+ bool Query::MatchesAllDocuments () const {
61
+ return filters_.empty () && limit_ == kNoLimit && !start_at_ && !end_at_ &&
62
+ (explicit_order_bys_.empty () ||
63
+ (explicit_order_bys_.size () == 1 &&
64
+ explicit_order_bys_.front ().field ().IsKeyFieldPath ()));
65
+ }
66
+
60
67
const FieldPath* Query::InequalityFilterField () const {
61
68
for (const auto & filter : filters_) {
62
69
if (filter.IsInequality ()) {
Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ class Query {
99
99
return collection_group_ != nullptr ;
100
100
}
101
101
102
+ /* *
103
+ * Returns true if this query does not specify any query constraints that
104
+ * could remove results.
105
+ */
106
+ bool MatchesAllDocuments () const ;
107
+
102
108
/* * The filters on the documents returned by the query. */
103
109
const FilterList& filters () const {
104
110
return filters_;
Original file line number Diff line number Diff line change @@ -708,6 +708,29 @@ TEST(QueryTest, CanonicalIDs) {
708
708
" desc|lb:b:OAK1000|ub:a:SFO2000" ));
709
709
}
710
710
711
+ TEST (QueryTest, MatchesAllDocuments) {
712
+ auto baseQuery = testutil::Query (" coll" );
713
+ EXPECT_TRUE (baseQuery.MatchesAllDocuments ());
714
+
715
+ auto query = baseQuery.AddingOrderBy (OrderBy (" __name__" ));
716
+ EXPECT_TRUE (query.MatchesAllDocuments ());
717
+
718
+ query = baseQuery.AddingOrderBy (OrderBy (" foo" ));
719
+ EXPECT_FALSE (query.MatchesAllDocuments ());
720
+
721
+ query = baseQuery.AddingFilter (Filter (" foo" , " ==" , " bar" ));
722
+ EXPECT_FALSE (query.MatchesAllDocuments ());
723
+
724
+ query = baseQuery.WithLimit (1 );
725
+ EXPECT_FALSE (query.MatchesAllDocuments ());
726
+
727
+ query = baseQuery.StartingAt (Bound ({Value (" SFO" )}, true ));
728
+ EXPECT_FALSE (query.MatchesAllDocuments ());
729
+
730
+ query = baseQuery.StartingAt (Bound ({Value (" OAK" )}, true ));
731
+ EXPECT_FALSE (query.MatchesAllDocuments ());
732
+ }
733
+
711
734
} // namespace core
712
735
} // namespace firestore
713
736
} // namespace firebase
You can’t perform that action at this time.
0 commit comments