-
Notifications
You must be signed in to change notification settings - Fork 627
add update time to FieldIndex #2984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,29 +56,32 @@ public String toString() { | |
} | ||
} | ||
|
||
private final String collectionId; | ||
private final String collectionGroup; | ||
private final int indexId; | ||
private final List<Segment> segments; | ||
private final SnapshotVersion version; | ||
|
||
public FieldIndex(String collectionId, int indexId) { | ||
this.collectionId = collectionId; | ||
public FieldIndex(String collectionGroup, int indexId) { | ||
this.collectionGroup = collectionGroup; | ||
this.segments = new ArrayList<>(); | ||
this.indexId = indexId; | ||
this.version = SnapshotVersion.NONE; | ||
} | ||
|
||
public FieldIndex(String collectionId) { | ||
this(collectionId, -1); | ||
} | ||
|
||
FieldIndex(String collectionId, int indexId, List<Segment> segments) { | ||
this.collectionId = collectionId; | ||
FieldIndex(String collectionGroup, int indexId, List<Segment> segments, SnapshotVersion version) { | ||
this.collectionGroup = collectionGroup; | ||
this.segments = segments; | ||
this.indexId = indexId; | ||
this.version = version; | ||
} | ||
|
||
/** The collection ID this index applies to. */ | ||
public String getCollectionId() { | ||
return collectionId; | ||
public String getCollectionGroup() { | ||
return collectionGroup; | ||
} | ||
|
||
/** | ||
|
@@ -97,6 +100,10 @@ public int segmentCount() { | |
return segments.size(); | ||
} | ||
|
||
public SnapshotVersion getVersion() { | ||
return version; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Iterator<Segment> iterator() { | ||
|
@@ -107,7 +114,12 @@ public Iterator<Segment> iterator() { | |
public FieldIndex withAddedField(FieldPath fieldPath, Segment.Kind kind) { | ||
List<Segment> newSegments = new ArrayList<>(segments); | ||
newSegments.add(new AutoValue_FieldIndex_Segment(fieldPath, kind)); | ||
return new FieldIndex(collectionId, indexId, newSegments); | ||
return new FieldIndex(collectionGroup, indexId, newSegments, version); | ||
} | ||
|
||
/** Returns a new field index with the updated version. */ | ||
public FieldIndex withVersion(SnapshotVersion version) { | ||
return new FieldIndex(collectionGroup, indexId, segments, version); | ||
} | ||
|
||
@Override | ||
|
@@ -118,18 +130,22 @@ public boolean equals(Object o) { | |
FieldIndex fieldIndex = (FieldIndex) o; | ||
|
||
if (!segments.equals(fieldIndex.segments)) return false; | ||
return collectionId.equals(fieldIndex.collectionId); | ||
if (!version.equals(fieldIndex.version)) return false; | ||
return collectionGroup.equals(fieldIndex.collectionGroup); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateTime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = collectionId.hashCode(); | ||
int result = collectionGroup.hashCode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateTime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
result = 31 * result + segments.hashCode(); | ||
result = 31 * result + version.hashCode(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("FieldIndex{collectionId='%s', segments=%s}", collectionId, segments); | ||
return String.format( | ||
"FieldIndex{collectionGroup='%s', segments=%s, version=%s}", | ||
collectionGroup, segments, version); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,15 @@ | |
import static com.google.firebase.firestore.testutil.TestUtil.orderBy; | ||
import static com.google.firebase.firestore.testutil.TestUtil.path; | ||
import static com.google.firebase.firestore.testutil.TestUtil.query; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import com.google.firebase.Timestamp; | ||
import com.google.firebase.firestore.core.Query; | ||
import com.google.firebase.firestore.model.DocumentKey; | ||
import com.google.firebase.firestore.model.FieldIndex; | ||
import com.google.firebase.firestore.model.MutableDocument; | ||
import com.google.firebase.firestore.model.SnapshotVersion; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -265,6 +268,19 @@ public void testCollectionGroup() { | |
verifyResults(query, "coll1/doc1", "coll2/doc2/coll1/doc1"); | ||
} | ||
|
||
@Test | ||
public void testUpdateTime() { | ||
indexManager.addFieldIndex( | ||
new FieldIndex("coll1") | ||
.withAddedField(field("value"), FieldIndex.Segment.Kind.ORDERED) | ||
.withVersion(new SnapshotVersion(new Timestamp(10, 20)))); | ||
|
||
List<FieldIndex> indexes = ((SQLiteIndexManager) indexManager).getFieldIndexes(); | ||
assertEquals(indexes.size(), 1); | ||
FieldIndex index = indexes.get(0); | ||
assertEquals(index.getVersion(), new SnapshotVersion(new Timestamp(10, 20))); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems better suited for our serialization tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test here checks that the persistence queries in |
||
|
||
private void addDoc(String key, Map<String, Object> data) { | ||
MutableDocument doc = doc(key, 1, data); | ||
indexManager.addIndexEntries(doc); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use SnapshotVersion for seconds+nanos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.