Skip to content

Firestore COUNT API #1174

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 28 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f58cad4
Firestore COUNT API
tom-andersen Dec 19, 2022
8eec324
Exempt from go/allstar check (#1173)
chkuang-g Dec 19, 2022
3c704e0
Token-changed listeners for iOS AppCheck (#1172)
AlmostMatt Dec 20, 2022
2cb8eb2
[macOS sandbox mode] Application group name mangling for semaphores (…
DellaBitta Dec 21, 2022
b59f275
Setup Desktop test workflow that detects C++ SDK breakage caused by i…
sunmou99 Dec 27, 2022
33c1831
[Bugfx] Fix Nightly Test Report template (#1181)
sunmou99 Jan 3, 2023
40e7025
Reduce number of RewardedAd loads on iOS in CI (#1180)
DellaBitta Jan 3, 2023
2810bef
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
371b820
Firestore COUNT implementation (WIP)
tom-andersen Jan 30, 2023
e19f512
Merge remote-tracking branch 'origin/main' into tomandersen/countAPI
tom-andersen Jan 30, 2023
00570d7
Fix linting
tom-andersen Jan 30, 2023
1f3f40d
Fix linting
tom-andersen Jan 30, 2023
bed0cea
Fix linking
tom-andersen Jan 31, 2023
eb61c87
Merge remote-tracking branch 'origin/main' into tomandersen/countAPI
tom-andersen Jan 31, 2023
e6bb4df
Cleanup
tom-andersen Jan 31, 2023
088560d
Fix release notes
tom-andersen Jan 31, 2023
d928ae8
Format
tom-andersen Jan 31, 2023
c08a1ba
Fixes from review
tom-andersen Feb 8, 2023
dfa4248
Formatting
tom-andersen Feb 8, 2023
94fcdef
Responding to PR comments.
tom-andersen Feb 9, 2023
e9502a3
Add Hash
tom-andersen Feb 10, 2023
a4d88eb
Add Hash
tom-andersen Feb 10, 2023
d2d6d36
Fix copyright year
tom-andersen Feb 10, 2023
cedc0e2
Rename
tom-andersen Feb 10, 2023
04eca2e
Format
tom-andersen Feb 10, 2023
dc6e00c
Rename
tom-andersen Feb 10, 2023
281d2b5
Fixup constructor/assignment parameter naming.
tom-andersen Feb 10, 2023
398a262
Format
tom-andersen Feb 10, 2023
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
3 changes: 1 addition & 2 deletions firestore/src/common/aggregate_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ AggregateQuery::AggregateQuery(AggregateQuery&& query) {

AggregateQuery::AggregateQuery(AggregateQueryInternal* internal)
: internal_(internal) {
// NOTE: We don't assert internal != nullptr here since internal can be
// nullptr when called by the CollectionReference copy constructor.
SIMPLE_HARD_ASSERT(internal != nullptr);
CleanupFnQuery::Register(this, internal_);
}

Expand Down
6 changes: 6 additions & 0 deletions firestore/src/common/aggregate_query_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "firestore/src/include/firebase/firestore/aggregate_query_snapshot.h"

#include "firestore/src/common/cleanup.h"
#include "firestore/src/common/util.h"
#include "firestore/src/include/firebase/firestore/aggregate_query.h"

#if defined(__ANDROID__)
Expand Down Expand Up @@ -103,5 +104,10 @@ int64_t AggregateQuerySnapshot::count() const {
return internal_->count();
}

bool operator==(const AggregateQuerySnapshot& lhs,
const AggregateQuerySnapshot& rhs) {
return EqualityCompare(lhs.internal_, rhs.internal_);
}

} // namespace firestore
} // namespace firebase
4 changes: 2 additions & 2 deletions firestore/src/include/firebase/firestore/aggregate_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class Query;
class AggregateQuery {
public:
/**
* @brief AggregateQuery an invalid Query that has to be reassigned before it
* can be used.
* @brief Creates an invalid AggregateQuery that has to be reassigned before
* it can be used.
*
* Calling any member function on an invalid AggregateQuery will be a no-op.
* If the function returns a value, it will return a zero, empty, or invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ class AggregateQuery;
class AggregateQuerySnapshotInternal;

/**
* @brief A QuerySnapshot contains zero or more DocumentSnapshot objects.
*
* QuerySnapshot can be iterated using a range-based for loop, and its size can
* be inspected with empty() and size().
* @brief The results of executing an AggregateQuery.
*
* @note Firestore classes are not meant to be subclassed except for use in test
* mocks. Subclassing is not supported in production code and new SDK releases
Expand All @@ -39,7 +36,7 @@ class AggregateQuerySnapshotInternal;
class AggregateQuerySnapshot {
public:
/**
* @brief AggregateQuerySnapshot an invalid Query that has to be reassigned
* @brief Creates an invalid AggregateQuerySnapshot that has to be reassigned
* before it can be used.
*
* Calling any member function on an invalid AggregateQuerySnapshot will be a
Expand Down
7 changes: 3 additions & 4 deletions firestore/src/main/aggregate_query_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ Query AggregateQueryInternal::query() {

Future<AggregateQuerySnapshot> AggregateQueryInternal::Get(
AggregateSource source) {
auto aggregate_query = aggregate_query_;
auto promise =
promise_factory_.CreatePromise<AggregateQuerySnapshot>(AsyncApis::kGet);
// TODO(tomandersen) Is there a better way to pass `aggregate_query_` than
// through `this`
aggregate_query_.Get(
[this, promise](util::StatusOr<int64_t> maybe_value) mutable {
[aggregate_query, promise](util::StatusOr<int64_t> maybe_value) mutable {
if (maybe_value.ok()) {
int64_t count = maybe_value.ValueOrDie();
AggregateQuerySnapshotInternal internal =
AggregateQuerySnapshotInternal(aggregate_query_, count);
AggregateQuerySnapshotInternal(aggregate_query, count);
AggregateQuerySnapshot snapshot = MakePublic(std::move(internal));
promise.SetValue(std::move(snapshot));
} else {
Expand Down
1 change: 0 additions & 1 deletion firestore/src/main/aggregate_query_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace firestore {
class AggregateQueryInternal {
public:
explicit AggregateQueryInternal(api::AggregateQuery&& aggregate_query);
~AggregateQueryInternal() = default;

FirestoreInternal* firestore_internal();
const FirestoreInternal* firestore_internal() const;
Expand Down
15 changes: 12 additions & 3 deletions firestore/src/main/aggregate_query_snapshot_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ namespace firebase {
namespace firestore {

AggregateQuerySnapshotInternal::AggregateQuerySnapshotInternal(
api::AggregateQuery aggregate_query, int64_t count_result)
: aggregate_query_(aggregate_query), count_result(count_result) {}
api::AggregateQuery&& aggregate_query, int64_t count_result)
: aggregate_query_(std::move(aggregate_query)),
count_result_(count_result) {}

FirestoreInternal* AggregateQuerySnapshotInternal::firestore_internal() {
return GetFirestoreInternal(&aggregate_query_.query());
Expand All @@ -39,7 +40,15 @@ AggregateQuery AggregateQuerySnapshotInternal::query() const {
return MakePublic(api::AggregateQuery(aggregate_query_));
}

int64_t AggregateQuerySnapshotInternal::count() const { return count_result; }
int64_t AggregateQuerySnapshotInternal::count() const { return count_result_; }

bool operator==(const AggregateQuerySnapshotInternal& lhs,
const AggregateQuerySnapshotInternal& rhs) {
// TODO(tomandersen) - there needs to be equals operator defined on
// api::AggregateQuery
return lhs.aggregate_query_.query() == rhs.aggregate_query_.query() &&
lhs.count_result_ == rhs.count_result_;
}

} // namespace firestore
} // namespace firebase
4 changes: 2 additions & 2 deletions firestore/src/main/aggregate_query_snapshot_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace firestore {

class AggregateQuerySnapshotInternal {
public:
explicit AggregateQuerySnapshotInternal(api::AggregateQuery aggregate_query,
explicit AggregateQuerySnapshotInternal(api::AggregateQuery&& aggregate_query,
int64_t count);

FirestoreInternal* firestore_internal();
Expand All @@ -47,7 +47,7 @@ class AggregateQuerySnapshotInternal {

private:
api::AggregateQuery aggregate_query_;
int64_t count_result;
int64_t count_result_;
};

inline bool operator!=(const AggregateQuerySnapshotInternal& lhs,
Expand Down
4 changes: 3 additions & 1 deletion release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ code.

## Release Notes
### Upcoming Release
- Firestore: Add Count API.
- Changes
- Added `Query::Count()`, which fetches the number of documents in the result
set without actually downloading the documents ([#1174](https://github.com/firebase/firebase-cpp-sdk/pull/1174)).

### 10.4.0
- Changes
Expand Down