Skip to content

Mila/test mieq race issue #12818

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

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
53eb2f8
initial code
milaGGL Jul 27, 2023
95850ff
add integration tests
milaGGL Jul 27, 2023
14514de
remove single inequality functions
milaGGL Jul 27, 2023
34dd2e9
include set
milaGGL Jul 28, 2023
1141850
update target index matcher
milaGGL Jul 28, 2023
088733b
update code
milaGGL Aug 1, 2023
d114ddc
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 2, 2023
daca229
add implicit order by unit tests
milaGGL Aug 2, 2023
2d5839a
fix typo
milaGGL Aug 2, 2023
ec3ef29
fix typo
milaGGL Aug 2, 2023
8656303
Update query.cc
milaGGL Aug 2, 2023
09adc00
resolve comments
milaGGL Aug 11, 2023
e8b74f0
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 11, 2023
e972262
Update query_test.cc
milaGGL Aug 11, 2023
e5d926e
Update CHANGELOG.md
milaGGL Aug 11, 2023
e0b09a9
add more unit tests for orderby normalization
milaGGL Aug 17, 2023
20e2295
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 17, 2023
a75fdda
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 24, 2023
92a5889
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 29, 2023
bc0759d
CSI compatibility
cherylEnkidu Aug 30, 2023
49898b6
Address feedback get from web review
cherylEnkidu Aug 31, 2023
abe383c
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Aug 31, 2023
a573b6a
resolve comments
milaGGL Aug 31, 2023
ee0046c
Merge branch 'master' into mila/multiple-inequality-support
milaGGL Sep 1, 2023
008a53a
Merge branch 'main' into mila/test-mieq-race-issue
milaGGL Apr 19, 2024
2e96691
format
cherylEnkidu Apr 19, 2024
bb91ee0
fix building error
milaGGL Apr 19, 2024
6275550
Merge branch 'mila/test-mieq-race-issue' of https://github.com/fireba…
milaGGL Apr 19, 2024
e4d9bb8
format
milaGGL Apr 19, 2024
fb18707
Update FIRQueryTests.mm
milaGGL Apr 19, 2024
8f8e7b7
format
milaGGL Apr 19, 2024
f5da2c8
Update field_filter.cc
milaGGL May 15, 2024
f35ca7f
Revert "Update field_filter.cc"
milaGGL May 16, 2024
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
30 changes: 20 additions & 10 deletions Firestore/core/src/core/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ absl::optional<Operator> Query::FindOpInsideFilters(
}

const std::vector<OrderBy>& Query::normalized_order_bys() const {
return memoized_normalized_order_bys_->memoize([&]() {
if (memoized_normalized_order_bys_.empty()) {
// Any explicit order by fields should be added as is.
std::vector<OrderBy> result = explicit_order_bys_;
std::set<FieldPath> fieldsNormalized;
Expand Down Expand Up @@ -127,8 +127,9 @@ const std::vector<OrderBy>& Query::normalized_order_bys() const {
result.push_back(OrderBy(FieldPath::KeyFieldPath(), last_direction));
}

return result;
});
memoized_normalized_order_bys_ = std::move(result);
}
return memoized_normalized_order_bys_;
}

LimitType Query::limit_type() const {
Expand Down Expand Up @@ -297,16 +298,23 @@ std::string Query::ToString() const {
}

const Target& Query::ToTarget() const& {
return memoized_target_->memoize(
[&]() { return ToTarget(normalized_order_bys()); });
if (memoized_target == nullptr) {
memoized_target = ToTarget(normalized_order_bys());
}

return *memoized_target;
}

const Target& Query::ToAggregateTarget() const& {
return memoized_aggregate_target_->memoize(
[&]() { return ToTarget(explicit_order_bys_); });
if (memoized_aggregate_target == nullptr) {
memoized_aggregate_target = ToTarget(explicit_order_bys_);
}

return *memoized_aggregate_target;
}

Target Query::ToTarget(const std::vector<OrderBy>& order_bys) const {
const std::shared_ptr<const Target> Query::ToTarget(
const std::vector<OrderBy>& order_bys) const& {
if (limit_type_ == LimitType::Last) {
// Flip the orderBy directions since we want the last results
std::vector<OrderBy> new_order_bys;
Expand All @@ -327,11 +335,13 @@ Target Query::ToTarget(const std::vector<OrderBy>& order_bys) const {
start_at_->position(), start_at_->inclusive())}
: absl::nullopt;

return Target(path(), collection_group(), filters(), new_order_bys, limit_,
Target target(path(), collection_group(), filters(), new_order_bys, limit_,
new_start_at, new_end_at);
return std::make_shared<Target>(std::move(target));
} else {
return Target(path(), collection_group(), filters(), order_bys, limit_,
Target target(path(), collection_group(), filters(), order_bys, limit_,
start_at(), end_at());
return std::make_shared<Target>(std::move(target));
}
}

Expand Down
26 changes: 8 additions & 18 deletions Firestore/core/src/core/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "Firestore/core/src/core/target.h"
#include "Firestore/core/src/model/model_fwd.h"
#include "Firestore/core/src/model/resource_path.h"
#include "Firestore/core/src/util/thread_safe_memoizer.h"

namespace firebase {
namespace firestore {
Expand Down Expand Up @@ -281,34 +280,25 @@ class Query {
// sort at the end.
std::vector<OrderBy> explicit_order_bys_;

// The memoized list of sort orders.
mutable std::vector<OrderBy> memoized_normalized_order_bys_;

int32_t limit_ = Target::kNoLimit;
LimitType limit_type_ = LimitType::None;

absl::optional<Bound> start_at_;
absl::optional<Bound> end_at_;

Target ToTarget(const std::vector<OrderBy>& order_bys) const;

// For properties below, use a `std::shared_ptr<ThreadSafeMemoizer>` rather
// than using `ThreadSafeMemoizer` directly so that this class is copyable
// (`ThreadSafeMemoizer` is not copyable because of its `std::once_flag`
// member variable, which is not copyable).

// The memoized list of sort orders.
mutable std::shared_ptr<util::ThreadSafeMemoizer<std::vector<OrderBy>>>
memoized_normalized_order_bys_{
std::make_shared<util::ThreadSafeMemoizer<std::vector<OrderBy>>>()};

// The corresponding Target of this Query instance.
mutable std::shared_ptr<util::ThreadSafeMemoizer<Target>> memoized_target_{
std::make_shared<util::ThreadSafeMemoizer<Target>>()};
mutable std::shared_ptr<const Target> memoized_target;

// The corresponding aggregate Target of this Query instance. Unlike targets
// for non-aggregate queries, aggregate query targets do not contain
// normalized order-bys, they only contain explicit order-bys.
mutable std::shared_ptr<util::ThreadSafeMemoizer<Target>>
memoized_aggregate_target_{
std::make_shared<util::ThreadSafeMemoizer<Target>>()};
mutable std::shared_ptr<const Target> memoized_aggregate_target;

const std::shared_ptr<const Target> ToTarget(
const std::vector<OrderBy>& order_bys) const&;
};

bool operator==(const Query& lhs, const Query& rhs);
Expand Down
Loading