Skip to content

Commit ab57eed

Browse files
Adding base_writes proto field (#2066)
1 parent b508201 commit ab57eed

File tree

7 files changed

+140
-8
lines changed

7 files changed

+140
-8
lines changed

Firestore/Protos/cpp/firestore/local/mutation.pb.cc

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUT
112112
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::firestore::client::WriteBatch, batch_id_),
113113
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::firestore::client::WriteBatch, writes_),
114114
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::firestore::client::WriteBatch, local_write_time_),
115+
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::firestore::client::WriteBatch, base_writes_),
115116
};
116117
static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
117118
{ 0, -1, sizeof(::firestore::client::MutationQueue)},
@@ -150,14 +151,16 @@ void AddDescriptorsImpl() {
150151
"te.proto\032\037google/protobuf/timestamp.prot"
151152
"o\"N\n\rMutationQueue\022\"\n\032last_acknowledged_"
152153
"batch_id\030\001 \001(\005\022\031\n\021last_stream_token\030\002 \001("
153-
"\014\"\205\001\n\nWriteBatch\022\020\n\010batch_id\030\001 \001(\005\022/\n\006wr"
154+
"\014\"\273\001\n\nWriteBatch\022\020\n\010batch_id\030\001 \001(\005\022/\n\006wr"
154155
"ites\030\002 \003(\0132\037.google.firestore.v1beta1.Wr"
155156
"ite\0224\n\020local_write_time\030\003 \001(\0132\032.google.p"
156-
"rotobuf.TimestampB/\n#com.google.firebase"
157-
".firestore.protoP\001\242\002\005FSTPBb\006proto3"
157+
"rotobuf.Timestamp\0224\n\013base_writes\030\004 \003(\0132\037"
158+
".google.firestore.v1beta1.WriteB/\n#com.g"
159+
"oogle.firebase.firestore.protoP\001\242\002\005FSTPB"
160+
"b\006proto3"
158161
};
159162
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
160-
descriptor, 394);
163+
descriptor, 448);
161164
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
162165
"firestore/local/mutation.proto", &protobuf_RegisterTypes);
163166
::protobuf_google_2ffirestore_2fv1beta1_2fwrite_2eproto::AddDescriptors();
@@ -476,10 +479,14 @@ void WriteBatch::clear_local_write_time() {
476479
}
477480
local_write_time_ = NULL;
478481
}
482+
void WriteBatch::clear_base_writes() {
483+
base_writes_.Clear();
484+
}
479485
#if !defined(_MSC_VER) || _MSC_VER >= 1900
480486
const int WriteBatch::kBatchIdFieldNumber;
481487
const int WriteBatch::kWritesFieldNumber;
482488
const int WriteBatch::kLocalWriteTimeFieldNumber;
489+
const int WriteBatch::kBaseWritesFieldNumber;
483490
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
484491

485492
WriteBatch::WriteBatch()
@@ -494,6 +501,7 @@ WriteBatch::WriteBatch(const WriteBatch& from)
494501
: ::google::protobuf::Message(),
495502
_internal_metadata_(NULL),
496503
writes_(from.writes_),
504+
base_writes_(from.base_writes_),
497505
_cached_size_(0) {
498506
_internal_metadata_.MergeFrom(from._internal_metadata_);
499507
if (from.has_local_write_time()) {
@@ -551,6 +559,7 @@ void WriteBatch::Clear() {
551559
(void) cached_has_bits;
552560

553561
writes_.Clear();
562+
base_writes_.Clear();
554563
if (GetArenaNoVirtual() == NULL && local_write_time_ != NULL) {
555564
delete local_write_time_;
556565
}
@@ -606,6 +615,17 @@ bool WriteBatch::MergePartialFromCodedStream(
606615
break;
607616
}
608617

618+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
619+
case 4: {
620+
if (static_cast< ::google::protobuf::uint8>(tag) ==
621+
static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) {
622+
DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(input, add_base_writes()));
623+
} else {
624+
goto handle_unusual;
625+
}
626+
break;
627+
}
628+
609629
default: {
610630
handle_unusual:
611631
if (tag == 0) {
@@ -650,6 +670,13 @@ void WriteBatch::SerializeWithCachedSizes(
650670
3, *this->local_write_time_, output);
651671
}
652672

673+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
674+
for (unsigned int i = 0,
675+
n = static_cast<unsigned int>(this->base_writes_size()); i < n; i++) {
676+
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
677+
4, this->base_writes(static_cast<int>(i)), output);
678+
}
679+
653680
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
654681
::google::protobuf::internal::WireFormat::SerializeUnknownFields(
655682
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output);
@@ -684,6 +711,14 @@ ::google::protobuf::uint8* WriteBatch::InternalSerializeWithCachedSizesToArray(
684711
3, *this->local_write_time_, deterministic, target);
685712
}
686713

714+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
715+
for (unsigned int i = 0,
716+
n = static_cast<unsigned int>(this->base_writes_size()); i < n; i++) {
717+
target = ::google::protobuf::internal::WireFormatLite::
718+
InternalWriteMessageToArray(
719+
4, this->base_writes(static_cast<int>(i)), deterministic, target);
720+
}
721+
687722
if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) {
688723
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
689724
(::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target);
@@ -712,6 +747,17 @@ size_t WriteBatch::ByteSizeLong() const {
712747
}
713748
}
714749

750+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
751+
{
752+
unsigned int count = static_cast<unsigned int>(this->base_writes_size());
753+
total_size += 1UL * count;
754+
for (unsigned int i = 0; i < count; i++) {
755+
total_size +=
756+
::google::protobuf::internal::WireFormatLite::MessageSize(
757+
this->base_writes(static_cast<int>(i)));
758+
}
759+
}
760+
715761
// .google.protobuf.Timestamp local_write_time = 3;
716762
if (this->has_local_write_time()) {
717763
total_size += 1 +
@@ -756,6 +802,7 @@ void WriteBatch::MergeFrom(const WriteBatch& from) {
756802
(void) cached_has_bits;
757803

758804
writes_.MergeFrom(from.writes_);
805+
base_writes_.MergeFrom(from.base_writes_);
759806
if (from.has_local_write_time()) {
760807
mutable_local_write_time()->::google::protobuf::Timestamp::MergeFrom(from.local_write_time());
761808
}
@@ -789,6 +836,7 @@ void WriteBatch::Swap(WriteBatch* other) {
789836
void WriteBatch::InternalSwap(WriteBatch* other) {
790837
using std::swap;
791838
writes_.InternalSwap(&other->writes_);
839+
base_writes_.InternalSwap(&other->base_writes_);
792840
swap(local_write_time_, other->local_write_time_);
793841
swap(batch_id_, other->batch_id_);
794842
_internal_metadata_.Swap(&other->_internal_metadata_);

Firestore/Protos/cpp/firestore/local/mutation.pb.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,18 @@ class WriteBatch : public ::google::protobuf::Message /* @@protoc_insertion_poin
292292
const ::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write >&
293293
writes() const;
294294

295+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
296+
int base_writes_size() const;
297+
void clear_base_writes();
298+
static const int kBaseWritesFieldNumber = 4;
299+
const ::google::firestore::v1beta1::Write& base_writes(int index) const;
300+
::google::firestore::v1beta1::Write* mutable_base_writes(int index);
301+
::google::firestore::v1beta1::Write* add_base_writes();
302+
::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write >*
303+
mutable_base_writes();
304+
const ::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write >&
305+
base_writes() const;
306+
295307
// .google.protobuf.Timestamp local_write_time = 3;
296308
bool has_local_write_time() const;
297309
void clear_local_write_time();
@@ -312,6 +324,7 @@ class WriteBatch : public ::google::protobuf::Message /* @@protoc_insertion_poin
312324

313325
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
314326
::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write > writes_;
327+
::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write > base_writes_;
315328
::google::protobuf::Timestamp* local_write_time_;
316329
::google::protobuf::int32 batch_id_;
317330
mutable int _cached_size_;
@@ -486,6 +499,33 @@ inline void WriteBatch::set_allocated_local_write_time(::google::protobuf::Times
486499
// @@protoc_insertion_point(field_set_allocated:firestore.client.WriteBatch.local_write_time)
487500
}
488501

502+
// repeated .google.firestore.v1beta1.Write base_writes = 4;
503+
inline int WriteBatch::base_writes_size() const {
504+
return base_writes_.size();
505+
}
506+
inline const ::google::firestore::v1beta1::Write& WriteBatch::base_writes(int index) const {
507+
// @@protoc_insertion_point(field_get:firestore.client.WriteBatch.base_writes)
508+
return base_writes_.Get(index);
509+
}
510+
inline ::google::firestore::v1beta1::Write* WriteBatch::mutable_base_writes(int index) {
511+
// @@protoc_insertion_point(field_mutable:firestore.client.WriteBatch.base_writes)
512+
return base_writes_.Mutable(index);
513+
}
514+
inline ::google::firestore::v1beta1::Write* WriteBatch::add_base_writes() {
515+
// @@protoc_insertion_point(field_add:firestore.client.WriteBatch.base_writes)
516+
return base_writes_.Add();
517+
}
518+
inline ::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write >*
519+
WriteBatch::mutable_base_writes() {
520+
// @@protoc_insertion_point(field_mutable_list:firestore.client.WriteBatch.base_writes)
521+
return &base_writes_;
522+
}
523+
inline const ::google::protobuf::RepeatedPtrField< ::google::firestore::v1beta1::Write >&
524+
WriteBatch::base_writes() const {
525+
// @@protoc_insertion_point(field_list:firestore.client.WriteBatch.base_writes)
526+
return base_writes_;
527+
}
528+
489529
#ifdef __GNUC__
490530
#pragma GCC diagnostic pop
491531
#endif // __GNUC__

Firestore/Protos/nanopb/firestore/local/mutation.nanopb.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ const pb_field_t firestore_client_MutationQueue_fields[3] = {
3535
PB_LAST_FIELD
3636
};
3737

38-
const pb_field_t firestore_client_WriteBatch_fields[4] = {
38+
const pb_field_t firestore_client_WriteBatch_fields[5] = {
3939
PB_FIELD( 1, INT32 , SINGULAR, STATIC , FIRST, firestore_client_WriteBatch, batch_id, batch_id, 0),
4040
PB_FIELD( 2, MESSAGE , REPEATED, POINTER , OTHER, firestore_client_WriteBatch, writes, batch_id, &google_firestore_v1beta1_Write_fields),
4141
PB_FIELD( 3, MESSAGE , SINGULAR, STATIC , OTHER, firestore_client_WriteBatch, local_write_time, writes, &google_protobuf_Timestamp_fields),
42+
PB_FIELD( 4, MESSAGE , REPEATED, POINTER , OTHER, firestore_client_WriteBatch, base_writes, local_write_time, &google_firestore_v1beta1_Write_fields),
4243
PB_LAST_FIELD
4344
};
4445

Firestore/Protos/nanopb/firestore/local/mutation.nanopb.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,30 @@ typedef struct _firestore_client_WriteBatch {
4646
pb_size_t writes_count;
4747
struct _google_firestore_v1beta1_Write *writes;
4848
google_protobuf_Timestamp local_write_time;
49+
pb_size_t base_writes_count;
50+
struct _google_firestore_v1beta1_Write *base_writes;
4951
/* @@protoc_insertion_point(struct:firestore_client_WriteBatch) */
5052
} firestore_client_WriteBatch;
5153

5254
/* Default values for struct fields */
5355

5456
/* Initializer values for message structs */
5557
#define firestore_client_MutationQueue_init_default {0, NULL}
56-
#define firestore_client_WriteBatch_init_default {0, 0, NULL, google_protobuf_Timestamp_init_default}
58+
#define firestore_client_WriteBatch_init_default {0, 0, NULL, google_protobuf_Timestamp_init_default, 0, NULL}
5759
#define firestore_client_MutationQueue_init_zero {0, NULL}
58-
#define firestore_client_WriteBatch_init_zero {0, 0, NULL, google_protobuf_Timestamp_init_zero}
60+
#define firestore_client_WriteBatch_init_zero {0, 0, NULL, google_protobuf_Timestamp_init_zero, 0, NULL}
5961

6062
/* Field tags (for use in manual encoding/decoding) */
6163
#define firestore_client_MutationQueue_last_acknowledged_batch_id_tag 1
6264
#define firestore_client_MutationQueue_last_stream_token_tag 2
6365
#define firestore_client_WriteBatch_batch_id_tag 1
6466
#define firestore_client_WriteBatch_writes_tag 2
6567
#define firestore_client_WriteBatch_local_write_time_tag 3
68+
#define firestore_client_WriteBatch_base_writes_tag 4
6669

6770
/* Struct field encoding specification for nanopb */
6871
extern const pb_field_t firestore_client_MutationQueue_fields[3];
69-
extern const pb_field_t firestore_client_WriteBatch_fields[4];
72+
extern const pb_field_t firestore_client_WriteBatch_fields[5];
7073

7174
/* Maximum encoded size of messages (where known) */
7275
/* firestore_client_MutationQueue_size depends on runtime parameters */

Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef GPB_ENUM(FSTPBWriteBatch_FieldNumber) {
102102
FSTPBWriteBatch_FieldNumber_BatchId = 1,
103103
FSTPBWriteBatch_FieldNumber_WritesArray = 2,
104104
FSTPBWriteBatch_FieldNumber_LocalWriteTime = 3,
105+
FSTPBWriteBatch_FieldNumber_BaseWritesArray = 4,
105106
};
106107

107108
/**
@@ -127,6 +128,22 @@ typedef GPB_ENUM(FSTPBWriteBatch_FieldNumber) {
127128
/** Test to see if @c localWriteTime has been set. */
128129
@property(nonatomic, readwrite) BOOL hasLocalWriteTime;
129130

131+
/**
132+
* A list of pseudo-writes that represent a partial base state from when this
133+
* write batch was initially created. When computing the local view batch,
134+
* these base_writes are applied prior to the real writes in order to
135+
* override certain document fields from the remote document cache. This is
136+
* necessary in the case of non-idempotent writes (e.g. numericAdd
137+
* transforms) to make sure that the local view of the modified documents
138+
* doesn't flicker if the remote document cache receives the result of the
139+
* non-idempotent write before the write is removed from the queue.
140+
*
141+
* These writes are never sent to the backend.
142+
**/
143+
@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GCFSWrite*> *baseWritesArray;
144+
/** The number of items in @c baseWritesArray without causing the array to be created. */
145+
@property(nonatomic, readonly) NSUInteger baseWritesArray_Count;
146+
130147
@end
131148

132149
NS_ASSUME_NONNULL_END

Firestore/Protos/objc/firestore/local/Mutation.pbobjc.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ @implementation FSTPBWriteBatch
126126
@dynamic batchId;
127127
@dynamic writesArray, writesArray_Count;
128128
@dynamic hasLocalWriteTime, localWriteTime;
129+
@dynamic baseWritesArray, baseWritesArray_Count;
129130

130131
typedef struct FSTPBWriteBatch__storage_ {
131132
uint32_t _has_storage_[1];
132133
int32_t batchId;
133134
NSMutableArray *writesArray;
134135
GPBTimestamp *localWriteTime;
136+
NSMutableArray *baseWritesArray;
135137
} FSTPBWriteBatch__storage_;
136138

137139
// This method is threadsafe because it is initially called
@@ -167,6 +169,15 @@ + (GPBDescriptor *)descriptor {
167169
.flags = GPBFieldOptional,
168170
.dataType = GPBDataTypeMessage,
169171
},
172+
{
173+
.name = "baseWritesArray",
174+
.dataTypeSpecific.className = GPBStringifySymbol(GCFSWrite),
175+
.number = FSTPBWriteBatch_FieldNumber_BaseWritesArray,
176+
.hasIndex = GPBNoHasBit,
177+
.offset = (uint32_t)offsetof(FSTPBWriteBatch__storage_, baseWritesArray),
178+
.flags = GPBFieldRepeated,
179+
.dataType = GPBDataTypeMessage,
180+
},
170181
};
171182
GPBDescriptor *localDescriptor =
172183
[GPBDescriptor allocDescriptorForClass:[FSTPBWriteBatch class]

Firestore/Protos/protos/firestore/local/mutation.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,16 @@ message WriteBatch {
5555

5656
// The local time at which the write batch was initiated.
5757
google.protobuf.Timestamp local_write_time = 3;
58+
59+
// A list of pseudo-writes that represent a partial base state from when this
60+
// write batch was initially created. When computing the local view batch,
61+
// these base_writes are applied prior to the real writes in order to
62+
// override certain document fields from the remote document cache. This is
63+
// necessary in the case of non-idempotent writes (e.g. numericAdd
64+
// transforms) to make sure that the local view of the modified documents
65+
// doesn't flicker if the remote document cache receives the result of the
66+
// non-idempotent write before the write is removed from the queue.
67+
//
68+
// These writes are never sent to the backend.
69+
repeated google.firestore.v1beta1.Write base_writes = 4;
5870
}

0 commit comments

Comments
 (0)