Skip to content

Commit 116091d

Browse files
committed
addressing comments #2
1 parent 4e83273 commit 116091d

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Firestore/core/src/firebase/firestore/core/sync_engine.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "Firestore/core/src/firebase/firestore/model/maybe_document.h"
4242
#include "Firestore/core/src/firebase/firestore/remote/remote_store.h"
4343
#include "Firestore/core/src/firebase/firestore/util/status.h"
44+
#include "absl/strings/string_view.h"
4445

4546
namespace firebase {
4647
namespace firestore {
@@ -167,7 +168,7 @@ class SyncEngine {
167168
* the results that was received. This can be used to indicate where to
168169
* continue receiving new doc changes for the query.
169170
*/
170-
const nanopb::ByteString resume_token() const {
171+
const nanopb::ByteString& resume_token() const {
171172
return resume_token_;
172173
}
173174

@@ -261,6 +262,8 @@ class SyncEngine {
261262
std::unordered_map<model::BatchId, std::vector<util::StatusCallback>>
262263
pending_writes_callbacks_;
263264

265+
// Shared pointers are used to avoid creating and storing two copies of the
266+
// same `QueryView` and for consistency with other platforms.
264267
/** QueryViews for all active queries, indexed by query. */
265268
std::unordered_map<Query, std::shared_ptr<QueryView>> query_views_by_query_;
266269

Firestore/core/src/firebase/firestore/core/sync_engine.mm

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
#include "Firestore/core/src/firebase/firestore/util/log.h"
3030
#include "Firestore/core/src/firebase/firestore/util/status.h"
3131

32+
namespace firebase {
33+
namespace firestore {
34+
namespace core {
35+
3236
namespace {
3337

34-
using firebase::firestore::Error;
35-
using firebase::firestore::model::ListenSequenceNumber;
36-
using firebase::firestore::util::Status;
38+
using firestore::Error;
39+
using model::ListenSequenceNumber;
40+
using util::Status;
3741

3842
// Limbo documents don't use persistence, and are eagerly GC'd. So, listens for
3943
// them don't need real sequence numbers.
@@ -48,9 +52,6 @@ bool ErrorIsInteresting(const Status& error) {
4852
}
4953

5054
} // namespace
51-
namespace firebase {
52-
namespace firestore {
53-
namespace core {
5455

5556
using auth::User;
5657
using local::LocalViewChanges;
@@ -89,6 +90,7 @@ bool ErrorIsInteresting(const Status& error) {
8990

9091
TargetId SyncEngine::Listen(Query query) {
9192
AssertCallbackExists("Listen");
93+
9294
HARD_ASSERT(query_views_by_query_.find(query) == query_views_by_query_.end(),
9395
"We already listen to query: %s", query.ToString());
9496

@@ -131,6 +133,7 @@ bool ErrorIsInteresting(const Status& error) {
131133

132134
void SyncEngine::StopListening(const Query& query) {
133135
AssertCallbackExists("StopListening");
136+
134137
auto query_view = query_views_by_query_[query];
135138
HARD_ASSERT(query_view, "Trying to stop listening to a query not found");
136139

@@ -231,13 +234,15 @@ bool ErrorIsInteresting(const Status& error) {
231234
if (it == limbo_resolutions_by_target_.end()) {
232235
continue;
233236
}
237+
234238
LimboResolution& limbo_resolution = it->second;
235239
// Since this is a limbo resolution lookup, it's for a single document and
236240
// it could be added, modified, or removed, but not a combination.
241+
auto changed_documents_count = change.added_documents().size() +
242+
change.modified_documents().size() +
243+
change.removed_documents().size();
237244
HARD_ASSERT(
238-
change.added_documents().size() + change.modified_documents().size() +
239-
change.removed_documents().size() <=
240-
1,
245+
changed_documents_count <= 1,
241246
"Limbo resolution for single document contains multiple changes.");
242247

243248
if (!change.added_documents().empty()) {
@@ -420,7 +425,7 @@ NoDocument doc(limbo_key, SnapshotVersion::None(),
420425

421426
for (const auto& entry : query_views_by_query_) {
422427
const auto& query_view = entry.second;
423-
const View& view = query_view->view();
428+
View& view = query_view->view();
424429
ViewDocumentChanges view_doc_changes = view.ComputeDocumentChanges(changes);
425430
if (view_doc_changes.needs_refill()) {
426431
// The query has a limit and some docs were removed/updated, so we need to
@@ -440,7 +445,7 @@ NoDocument doc(limbo_key, SnapshotVersion::None(),
440445
}
441446
}
442447
ViewChange view_change =
443-
query_view->view().ApplyChanges(view_doc_changes, target_changes);
448+
view.ApplyChanges(view_doc_changes, target_changes);
444449

445450
UpdateTrackedLimboDocuments(view_change.limbo_changes(),
446451
query_view->target_id());

0 commit comments

Comments
 (0)