Skip to content

Commit 418e3a6

Browse files
committed
merge in base branch
2 parents fd8ed65 + b51b545 commit 418e3a6

File tree

15 files changed

+54
-249
lines changed

15 files changed

+54
-249
lines changed

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Expression.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,6 @@ public protocol Expression: Sendable {
15581558

15591559
// MARK: Equivalence Operations
15601560

1561-
15621561
/// Creates a `BooleanExpr` that returns `true` if this expression is equivalent
15631562
/// to the given value.
15641563
///

Firestore/Swift/Source/SwiftAPI/Pipeline/RealtimePipeline.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ import Foundation
2121

2222
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
2323
struct PipelineListenOptions: Sendable, Equatable, Hashable {
24+
/// Defines how to handle server-generated timestamps that are not yet known locally
25+
/// during latency compensation.
26+
struct ServerTimestampBehavior: Sendable, Equatable, Hashable {
27+
/// The raw string value for the behavior, used for implementation and hashability.
28+
let rawValue: String
29+
/// Creates a new behavior with a private raw value.
30+
private init(rawValue: String) {
31+
self.rawValue = rawValue
32+
}
33+
34+
/// Fields dependent on server timestamps will be `nil` until the value is
35+
/// confirmed by the server.
36+
public static let none = ServerTimestampBehavior(rawValue: "none")
37+
38+
/// Fields dependent on server timestamps will receive a local, client-generated
39+
/// time estimate until the value is confirmed by the server.
40+
public static let estimate = ServerTimestampBehavior(rawValue: "estimate")
41+
42+
/// Fields dependent on server timestamps will hold the value from the last
43+
/// server-confirmed write until the new value is confirmed.
44+
public static let previous = ServerTimestampBehavior(rawValue: "previous")
45+
}
46+
2447
// MARK: - Stored Properties
2548

2649
/// The desired behavior for handling pending server timestamps.
@@ -46,31 +69,16 @@ struct PipelineListenOptions: Sendable, Equatable, Hashable {
4669
self.includeMetadataChanges = includeMetadataChanges
4770
self.source = source
4871
bridge = __PipelineListenOptionsBridge(
49-
serverTimestampBehavior: PipelineListenOptions
50-
.toRawValue(servertimestamp: self.serverTimestamps ?? .none),
72+
serverTimestampBehavior: (self.serverTimestamps ?? .none).rawValue,
5173
includeMetadata: self.includeMetadataChanges ?? false,
5274
source: self.source ?? ListenSource.default
5375
)
5476
}
55-
56-
private static func toRawValue(servertimestamp: ServerTimestampBehavior) -> String {
57-
switch servertimestamp {
58-
case .none:
59-
return "none"
60-
case .estimate:
61-
return "estimate"
62-
case .previous:
63-
return "previous"
64-
@unknown default:
65-
fatalError("Unknown server timestamp behavior")
66-
}
67-
}
6877
}
6978

7079
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
7180
struct RealtimePipeline: @unchecked Sendable {
7281
private var stages: [Stage]
73-
7482
let bridge: RealtimePipelineBridge
7583
let db: Firestore
7684

@@ -81,22 +89,18 @@ struct RealtimePipeline: @unchecked Sendable {
8189
}
8290

8391
struct Snapshot: Sendable {
84-
/// An array of all the results in the `Pipeline.Snapshot`.
92+
/// An array of all the results in the `PipelineSnapshot`.
8593
let results_cache: [PipelineResult]
8694

8795
public let changes: [PipelineResultChange]
8896
public let metadata: SnapshotMetadata
8997

9098
let bridge: __RealtimePipelineSnapshotBridge
91-
private var options: PipelineListenOptions
9299

93-
init(_ bridge: __RealtimePipelineSnapshotBridge,
94-
options: PipelineListenOptions) {
100+
init(_ bridge: __RealtimePipelineSnapshotBridge) {
95101
self.bridge = bridge
96-
self.options = options
97102
metadata = bridge.metadata
98-
results_cache = self.bridge.results
99-
.map { PipelineResult($0, options.serverTimestamps ?? .none) }
103+
results_cache = self.bridge.results.map { PipelineResult($0) }
100104
changes = self.bridge.changes.map { PipelineResultChange($0) }
101105
}
102106

@@ -109,17 +113,13 @@ struct RealtimePipeline: @unchecked Sendable {
109113
listener: @escaping (RealtimePipeline.Snapshot?, Error?) -> Void)
110114
-> ListenerRegistration {
111115
return bridge.addSnapshotListener(options: options.bridge) { snapshotBridge, error in
112-
if snapshotBridge != nil {
113-
listener(
114-
RealtimePipeline.Snapshot(
115-
snapshotBridge!,
116-
options: options
117-
),
118-
error
119-
)
120-
} else {
121-
listener(nil, error)
122-
}
116+
listener(
117+
RealtimePipeline.Snapshot(
118+
// TODO(pipeline): this needs to be fixed
119+
snapshotBridge!
120+
),
121+
error
122+
)
123123
}
124124
}
125125

Firestore/core/src/api/realtime_pipeline.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ RealtimePipeline::RealtimePipeline(const RealtimePipeline& other)
3737
: stages_(other.stages_),
3838
rewritten_stages_(other.rewritten_stages_),
3939
serializer_(std::make_unique<remote::Serializer>(
40-
other.serializer_->database_id())),
41-
listen_options_(other.listen_options()) {
40+
other.serializer_->database_id())) {
4241
}
4342

4443
RealtimePipeline& RealtimePipeline::operator=(const RealtimePipeline& other) {
@@ -47,7 +46,6 @@ RealtimePipeline& RealtimePipeline::operator=(const RealtimePipeline& other) {
4746
rewritten_stages_ = other.rewritten_stages_;
4847
serializer_ =
4948
std::make_unique<remote::Serializer>(other.serializer_->database_id());
50-
listen_options_ = other.listen_options();
5149
}
5250
return *this;
5351
}
@@ -72,7 +70,7 @@ RealtimePipeline::rewritten_stages() const {
7270
}
7371

7472
EvaluateContext RealtimePipeline::evaluate_context() const {
75-
return EvaluateContext(serializer_.get(), listen_options_);
73+
return EvaluateContext(serializer_.get());
7674
}
7775

7876
} // namespace api

Firestore/core/src/api/realtime_pipeline.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "Firestore/core/src/api/api_fwd.h"
2424
#include "Firestore/core/src/api/stages.h"
2525
#include "Firestore/core/src/core/core_fwd.h"
26-
#include "Firestore/core/src/core/listen_options.h"
2726

2827
namespace firebase {
2928
namespace firestore {
@@ -48,21 +47,14 @@ class RealtimePipeline {
4847

4948
EvaluateContext evaluate_context() const;
5049

51-
RealtimePipeline WithListenOptions(const core::ListenOptions& options) const {
52-
RealtimePipeline result(*this);
53-
result.listen_options_ = options;
54-
return result;
55-
}
56-
57-
const core::ListenOptions& listen_options() const {
58-
return listen_options_;
59-
}
50+
std::unique_ptr<api::ListenerRegistration> AddSnapshotListener(
51+
core::ListenOptions options,
52+
api::RealtimePipelineSnapshotListener&& listener);
6053

6154
private:
6255
std::vector<std::shared_ptr<EvaluableStage>> stages_;
6356
std::vector<std::shared_ptr<EvaluableStage>> rewritten_stages_;
6457
std::unique_ptr<remote::Serializer> serializer_;
65-
core::ListenOptions listen_options_;
6658
};
6759

6860
} // namespace api

Firestore/core/src/api/stages.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ class Stage {
5555

5656
class EvaluateContext {
5757
public:
58-
explicit EvaluateContext(remote::Serializer* serializer,
59-
core::ListenOptions options)
60-
: serializer_(serializer), listen_options_(std::move(options)) {
58+
explicit EvaluateContext(remote::Serializer* serializer)
59+
: serializer_(serializer) {
6160
}
6261

6362
const remote::Serializer& serializer() const {

Firestore/core/src/core/expressions_eval.cc

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@
3131
#include "Firestore/core/src/api/expressions.h"
3232
#include "Firestore/core/src/api/stages.h"
3333
#include "Firestore/core/src/model/mutable_document.h"
34-
#include "Firestore/core/src/model/server_timestamp_util.h"
3534
#include "Firestore/core/src/model/value_util.h" // For value helpers like IsArray, DeepClone
3635
#include "Firestore/core/src/nanopb/message.h" // Added for MakeMessage
3736
#include "Firestore/core/src/remote/serializer.h"
3837
#include "Firestore/core/src/util/hard_assert.h"
39-
#include "Firestore/core/src/util/log.h"
4038
#include "absl/strings/ascii.h" // For AsciiStrToLower/ToUpper (if needed later)
39+
#include "absl/strings/internal/utf8.h"
4140
#include "absl/strings/match.h" // For StartsWith, EndsWith, StrContains
4241
#include "absl/strings/str_cat.h" // For StrAppend
4342
#include "absl/strings/strip.h" // For StripAsciiWhitespace
@@ -313,32 +312,6 @@ std::unique_ptr<EvaluableExpr> FunctionToEvaluable(
313312
HARD_FAIL("Unsupported function name: %s", function.name());
314313
}
315314

316-
namespace {
317-
318-
nanopb::Message<google_firestore_v1_Value> GetServerTimestampValue(
319-
const api::EvaluateContext& context,
320-
const google_firestore_v1_Value& timestamp_sentinel) {
321-
if (context.listen_options().server_timestamp_behavior() ==
322-
ListenOptions::ServerTimestampBehavior::kEstimate) {
323-
google_firestore_v1_Value result;
324-
result.which_value_type = google_firestore_v1_Value_timestamp_value_tag;
325-
result.timestamp_value = model::GetLocalWriteTime(timestamp_sentinel);
326-
return nanopb::MakeMessage<google_firestore_v1_Value>(result);
327-
}
328-
329-
if (context.listen_options().server_timestamp_behavior() ==
330-
ListenOptions::ServerTimestampBehavior::kPrevious) {
331-
auto result = model::GetPreviousValue(timestamp_sentinel);
332-
if (result.has_value()) {
333-
return model::DeepClone(result.value());
334-
}
335-
}
336-
337-
return nanopb::MakeMessage<google_firestore_v1_Value>(model::NullValue());
338-
}
339-
340-
} // namespace
341-
342315
EvaluateResult CoreField::Evaluate(
343316
const api::EvaluateContext& context,
344317
const model::PipelineInputOutput& input) const {
@@ -367,11 +340,6 @@ EvaluateResult CoreField::Evaluate(
367340
// Return 'UNSET' if the field doesn't exist, otherwise the Value.
368341
const auto& result = input.field(field->field_path());
369342
if (result.has_value()) {
370-
if (model::IsServerTimestamp(result.value())) {
371-
return EvaluateResult::NewValue(
372-
GetServerTimestampValue(context, result.value()));
373-
}
374-
375343
// DeepClone the field value to avoid modifying the original.
376344
return EvaluateResult::NewValue(model::DeepClone(result.value()));
377345
} else {

Firestore/core/src/core/pipeline_util.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030
#include "Firestore/core/src/core/expressions_eval.h"
3131
#include "Firestore/core/src/core/filter.h"
3232
#include "Firestore/core/src/core/order_by.h"
33-
#include "Firestore/core/src/core/pipeline_run.h" // Contains RunPipeline, EvaluateContext
33+
#include "Firestore/core/src/core/pipeline_run.h"
3434
#include "Firestore/core/src/core/query.h"
3535
#include "Firestore/core/src/model/document.h"
36-
#include "Firestore/core/src/model/document_key.h"
3736
#include "Firestore/core/src/model/document_set.h"
3837
#include "Firestore/core/src/model/field_path.h"
3938
#include "Firestore/core/src/model/mutable_document.h"
@@ -46,7 +45,6 @@
4645
#include "absl/strings/str_cat.h"
4746
#include "absl/strings/str_format.h"
4847
#include "absl/strings/str_join.h"
49-
#include "absl/types/compare.h"
5048
#include "absl/types/optional.h"
5149
#include "absl/types/variant.h"
5250

Firestore/core/src/core/pipeline_util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "absl/types/optional.h"
2525
#include "absl/types/variant.h"
2626

27-
#include "Firestore/core/src/api/expressions.h"
2827
#include "Firestore/core/src/api/realtime_pipeline.h"
2928
#include "Firestore/core/src/api/stages.h"
3029
#include "Firestore/core/src/core/query.h"

Firestore/core/src/core/query_listener.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ QueryListener::QueryListener(QueryOrPipeline query,
6868
: query_(std::move(query)),
6969
options_(std::move(options)),
7070
listener_(std::move(listener)) {
71-
if (query_.IsPipeline()) {
72-
query_ = QueryOrPipeline(query_.pipeline().WithListenOptions(options_));
73-
}
7471
}
7572

7673
bool QueryListener::OnViewSnapshot(ViewSnapshot snapshot) {
@@ -199,4 +196,4 @@ void QueryListener::RaiseInitialEvent(const ViewSnapshot& snapshot) {
199196

200197
} // namespace core
201198
} // namespace firestore
202-
} // namespace firebase
199+
} // namespace firebase

Firestore/core/src/core/query_listener.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ class QueryListener {
6060

6161
virtual ~QueryListener() = default;
6262

63-
QueryOrPipeline& query() {
63+
const QueryOrPipeline& query() const {
6464
return query_;
6565
}
6666

67-
ListenOptions listen_options() {
68-
return options_;
69-
}
70-
7167
bool listens_to_remote_store() const {
7268
return options_.source() != ListenSource::Cache;
7369
}

0 commit comments

Comments
 (0)