Skip to content

Commit e5fdd37

Browse files
author
Brian Chen
committed
resolve comments
1 parent 2cdef90 commit e5fdd37

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalSerializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ public FieldIndex decodeFieldIndex(
322322
? FieldIndex.Segment.Kind.CONTAINS
323323
: FieldIndex.Segment.Kind.ORDERED);
324324
}
325-
fieldIndex = fieldIndex.withUpdateTime(new Timestamp(updateSeconds, updateNanos));
325+
fieldIndex =
326+
fieldIndex.withVersion(new SnapshotVersion(new Timestamp(updateSeconds, updateNanos)));
326327
return fieldIndex;
327328
}
328329
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public void addFieldIndex(FieldIndex index) {
110110
index.getCollectionGroup(),
111111
encodeFieldIndex(index),
112112
true,
113-
index.getUpdateTime().getSeconds(),
114-
index.getUpdateTime().getNanoseconds());
113+
index.getVersion().getTimestamp().getSeconds(),
114+
index.getVersion().getTimestamp().getNanoseconds());
115115
}
116116

117117
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/model/FieldIndex.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import androidx.annotation.NonNull;
1818
import com.google.auto.value.AutoValue;
19-
import com.google.firebase.Timestamp;
2019
import java.util.ArrayList;
2120
import java.util.Iterator;
2221
import java.util.List;
@@ -60,24 +59,24 @@ public String toString() {
6059
private final String collectionGroup;
6160
private final int indexId;
6261
private final List<Segment> segments;
63-
private final Timestamp updateTime;
62+
private final SnapshotVersion version;
6463

6564
public FieldIndex(String collectionGroup, int indexId) {
6665
this.collectionGroup = collectionGroup;
6766
this.segments = new ArrayList<>();
6867
this.indexId = indexId;
69-
this.updateTime = new Timestamp(0L, 0);
68+
this.version = SnapshotVersion.NONE;
7069
}
7170

7271
public FieldIndex(String collectionId) {
7372
this(collectionId, -1);
7473
}
7574

76-
FieldIndex(String collectionGroup, int indexId, List<Segment> segments, Timestamp updateTime) {
75+
FieldIndex(String collectionGroup, int indexId, List<Segment> segments, SnapshotVersion version) {
7776
this.collectionGroup = collectionGroup;
7877
this.segments = segments;
7978
this.indexId = indexId;
80-
this.updateTime = updateTime;
79+
this.version = version;
8180
}
8281

8382
/** The collection ID this index applies to. */
@@ -101,8 +100,8 @@ public int segmentCount() {
101100
return segments.size();
102101
}
103102

104-
public Timestamp getUpdateTime() {
105-
return updateTime;
103+
public SnapshotVersion getVersion() {
104+
return version;
106105
}
107106

108107
@NonNull
@@ -115,12 +114,12 @@ public Iterator<Segment> iterator() {
115114
public FieldIndex withAddedField(FieldPath fieldPath, Segment.Kind kind) {
116115
List<Segment> newSegments = new ArrayList<>(segments);
117116
newSegments.add(new AutoValue_FieldIndex_Segment(fieldPath, kind));
118-
return new FieldIndex(collectionGroup, indexId, newSegments, updateTime);
117+
return new FieldIndex(collectionGroup, indexId, newSegments, version);
119118
}
120119

121-
/** Returns a new field index with the updated updateTime. */
122-
public FieldIndex withUpdateTime(Timestamp updateTime) {
123-
return new FieldIndex(collectionGroup, indexId, segments, updateTime);
120+
/** Returns a new field index with the updated version. */
121+
public FieldIndex withVersion(SnapshotVersion version) {
122+
return new FieldIndex(collectionGroup, indexId, segments, version);
124123
}
125124

126125
@Override
@@ -131,19 +130,22 @@ public boolean equals(Object o) {
131130
FieldIndex fieldIndex = (FieldIndex) o;
132131

133132
if (!segments.equals(fieldIndex.segments)) return false;
133+
if (!version.equals(fieldIndex.version)) return false;
134134
return collectionGroup.equals(fieldIndex.collectionGroup);
135135
}
136136

137137
@Override
138138
public int hashCode() {
139139
int result = collectionGroup.hashCode();
140140
result = 31 * result + segments.hashCode();
141+
result = 31 * result + version.hashCode();
141142
return result;
142143
}
143144

144145
@Override
145146
public String toString() {
146147
return String.format(
147-
"FieldIndex{collectionGroup='%s', segments=%s}", collectionGroup, segments);
148+
"FieldIndex{collectionGroup='%s', segments=%s, version=%s}",
149+
collectionGroup, segments, version);
148150
}
149151
}

firebase-firestore/src/test/java/com/google/firebase/firestore/local/SQLiteIndexManagerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.firebase.firestore.model.DocumentKey;
3333
import com.google.firebase.firestore.model.FieldIndex;
3434
import com.google.firebase.firestore.model.MutableDocument;
35+
import com.google.firebase.firestore.model.SnapshotVersion;
3536
import java.util.Arrays;
3637
import java.util.List;
3738
import java.util.Map;
@@ -272,12 +273,12 @@ public void testUpdateTime() {
272273
indexManager.addFieldIndex(
273274
new FieldIndex("coll1")
274275
.withAddedField(field("value"), FieldIndex.Segment.Kind.ORDERED)
275-
.withUpdateTime(new Timestamp(10, 20)));
276+
.withVersion(new SnapshotVersion(new Timestamp(10, 20))));
276277

277278
List<FieldIndex> indexes = ((SQLiteIndexManager) indexManager).getFieldIndexes();
278279
assertEquals(indexes.size(), 1);
279280
FieldIndex index = indexes.get(0);
280-
assertEquals(index.getUpdateTime(), new Timestamp(10, 20));
281+
assertEquals(index.getVersion(), new SnapshotVersion(new Timestamp(10, 20)));
281282
}
282283

283284
private void addDoc(String key, Map<String, Object> data) {

0 commit comments

Comments
 (0)