Skip to content

Commit fd3247b

Browse files
Send target to backend before local processing (#9323)
* Send target to backend before local processing * Remove trailing whitespace
1 parent 0bc4258 commit fd3247b

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [changed] Queries are now send to the backend before the SDK starts local
3+
processing, which reduces overall Query latency.
24
- [changed] Add more details to the assertion failure in OrderBy::Compare() to
35
help with future debugging (#9258).
46

Firestore/core/src/core/sync_engine.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ TargetId SyncEngine::Listen(Query query) {
109109
"We already listen to query: %s", query.ToString());
110110

111111
TargetData target_data = local_store_->AllocateTarget(query.ToTarget());
112+
TargetId target_id = target_data.target_id();
113+
remote_store_->Listen(std::move(target_data));
114+
112115
ViewSnapshot view_snapshot =
113-
InitializeViewAndComputeSnapshot(query, target_data.target_id());
116+
InitializeViewAndComputeSnapshot(query, target_id);
114117
std::vector<ViewSnapshot> snapshots;
115118
// Not using the `std::initializer_list` constructor to avoid extra copies.
116119
snapshots.push_back(std::move(view_snapshot));
117120
sync_engine_callback_->OnViewSnapshots(std::move(snapshots));
118121

119-
// TODO(wuandy): move `target_data` into `Listen`.
120-
remote_store_->Listen(target_data);
121-
return target_data.target_id();
122+
return target_id;
122123
}
123124

124125
ViewSnapshot SyncEngine::InitializeViewAndComputeSnapshot(const Query& query,

Firestore/core/src/remote/remote_store.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ void RemoteStore::Shutdown() {
151151

152152
// Watch Stream
153153

154-
void RemoteStore::Listen(const TargetData& target_data) {
154+
void RemoteStore::Listen(TargetData target_data) {
155155
TargetId target_key = target_data.target_id();
156156
if (listen_targets_.find(target_key) != listen_targets_.end()) {
157157
return;
158158
}
159159

160160
// Mark this as something the client is currently listening for.
161-
listen_targets_[target_key] = target_data;
161+
listen_targets_[target_key] = std::move(target_data);
162162

163163
if (ShouldStartWatchStream()) {
164164
// The listen will be sent in `OnWatchStreamOpen`
165165
StartWatchStream();
166166
} else if (watch_stream_->IsOpen()) {
167-
SendWatchRequest(target_data);
167+
SendWatchRequest(listen_targets_[target_key]);
168168
}
169169
}
170170

Firestore/core/src/remote/remote_store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class RemoteStore : public TargetMetadataProvider,
159159
* It is a no-op if the target of the given target data is already being
160160
* listened to.
161161
*/
162-
void Listen(const local::TargetData& target_data);
162+
void Listen(local::TargetData target_data);
163163

164164
/**
165165
* Stops listening to the target with the given target ID.

0 commit comments

Comments
 (0)