Skip to content

Revert "Public count" #10252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2022
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
2 changes: 0 additions & 2 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Unreleased
- [feature] Added `Query.count()`, which fetches the number of documents in the
result set without actually downloading the documents (#10246).
- [fixed] Fixed compiler warning about `@param comparator` (#10226).

# 9.6.0
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Example/Tests/Integration/API/FIRCountTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#import <XCTest/XCTest.h>

#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h"
#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuerySnapshot.h"
#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateSource.h"
#import "Firestore/Source/API/FIRAggregateQuery+Internal.h"
#import "Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h"
#import "Firestore/Source/API/FIRQuery+Internal.h"

@interface FIRCountTests : FSTIntegrationTestCase
@end
Expand Down
27 changes: 25 additions & 2 deletions Firestore/Source/API/FIRAggregateQuery+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,35 @@
* limitations under the License.
*/

#import "FIRAggregateQuery.h"
// TODO(b/246760853): Move FIRAggregateQuery to public headers to release it.

#import "FIRAggregateSource+Internal.h"
#import "FIRQuery.h"

@interface FIRAggregateQuery (/* init */)
@class FIRAggregateQuerySnapshot;

/**
* An `AggregateQuery` computes some aggregation statistics from the result set of a base
* `Query`.
*/
NS_SWIFT_NAME(AggregateQuery)
@interface FIRAggregateQuery : NSObject

- (instancetype _Nonnull)init NS_UNAVAILABLE;
- (instancetype _Nonnull)initWithQuery:(FIRQuery *_Nonnull)query NS_DESIGNATED_INITIALIZER;

/** The base `Query` for this aggregate query. */
@property(nonatomic, readonly) FIRQuery *_Nonnull query;

/**
* Executes the aggregate query and reads back the results as a `FIRAggregateQuerySnapshot`.
*
* @param source indicates where the results should be fetched from.
* @param completion a block to execute once the results have been successfully read.
* snapshot will be `nil` only if error is `non-nil`.
*/
- (void)aggregationWithSource:(FIRAggregateSource)source
completion:(void (^_Nonnull)(FIRAggregateQuerySnapshot *_Nullable snapshot,
NSError *_Nullable error))completion
NS_SWIFT_NAME(aggregation(source:completion:));
@end
19 changes: 17 additions & 2 deletions Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@
* limitations under the License.
*/

#import "FIRAggregateQuerySnapshot.h"
// TODO(b/246760853): Move FIRAggregateQuerySnapshot to public headers to release it.

#import "FIRAggregateQuery+Internal.h"

@class FIRAggregateQuery;

@interface FIRAggregateQuerySnapshot (/* init */)
/**
* An `AggregateQuerySnapshot` contains results of a `AggregateQuery`.
*/
NS_SWIFT_NAME(AggregateQuerySnapshot)
@interface FIRAggregateQuerySnapshot : NSObject

- (instancetype _Nonnull)init NS_UNAVAILABLE;
- (instancetype _Nonnull)initWithCount:(int64_t)result
Query:(FIRAggregateQuery* _Nonnull)query NS_DESIGNATED_INITIALIZER;

/** The original `AggregateQuery` this snapshot is a result of. */
@property(nonatomic, readonly) FIRAggregateQuery* _Nonnull query;

/**
* The result of a document count aggregation. Null if no count aggregation is
* available in the result.
*/
@property(nonatomic, readonly) NSNumber* _Nullable count;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

#import <Foundation/Foundation.h>
// TODO(b/246760853): Move FIRAggregateSource to public headers to release it.

NS_ASSUME_NONNULL_BEGIN
#import <Foundation/Foundation.h>

/** Configures the behavior of `AggregateQuery.aggregateWithSource(source:completion:)`. */
typedef NS_ENUM(NSUInteger, FIRAggregateSource) {
Expand All @@ -28,5 +28,3 @@ typedef NS_ENUM(NSUInteger, FIRAggregateSource) {
*/
FIRAggregateSourceServer,
} NS_SWIFT_NAME(AggregateSource);

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions Firestore/Source/API/FIRQuery+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#import "FIRAggregateQuery+Internal.h"
#import "FIRQuery.h"

#include <memory>
Expand Down Expand Up @@ -47,6 +48,12 @@ NS_ASSUME_NONNULL_BEGIN
// TODO(orquery): This method will become public API. Change visibility and add documentation.
- (FIRQuery *)queryWhereFilter:(FIRFilter *)filter;

// TODO(b/246760853): This property will become public API.
/**
* An `AggregateQuery` counting the number of documents matching this query.
*/
@property(nonatomic, readonly) FIRAggregateQuery *count;

@end

NS_ASSUME_NONNULL_END
1 change: 0 additions & 1 deletion Firestore/Source/API/FIRQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <utility>
#include <vector>

#import "FIRAggregateQuery+Internal.h"
#import "FIRDocumentReference.h"
#import "FIRFirestoreErrors.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
Expand Down
49 changes: 0 additions & 49 deletions Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions Firestore/Source/Public/FirebaseFirestore/FIRQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#import "FIRFirestoreSource.h"
#import "FIRListenerRegistration.h"

@class FIRAggregateQuery;
@class FIRFieldPath;
@class FIRFirestore;
@class FIRQuerySnapshot;
Expand Down Expand Up @@ -543,13 +542,6 @@ NS_SWIFT_NAME(Query)
*/
- (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(at:));

#pragma mark - Aggregation

/**
* An `AggregateQuery` counting the number of documents matching this query.
*/
@property(nonatomic, readonly) FIRAggregateQuery *count;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,5 @@ let emptyBundle = """

XCTAssertNil(value, "value should be nil on success")
}

func testCount() async throws {
let collection = collectionRef()
try await collection.addDocument(data: [:])
let snapshot = try await collection.count.getAggregation(source: .server)
XCTAssertEqual(snapshot.count, 1)
}
}
#endif