17
17
import static com .google .firebase .firestore .model .DocumentCollections .emptyMutableDocumentMap ;
18
18
import static com .google .firebase .firestore .util .Assert .hardAssert ;
19
19
20
- import android .util .Pair ;
21
20
import androidx .annotation .NonNull ;
22
21
import com .google .firebase .database .collection .ImmutableSortedMap ;
23
22
import com .google .firebase .firestore .core .Query ;
34
33
final class MemoryRemoteDocumentCache implements RemoteDocumentCache {
35
34
36
35
/** Underlying cache of documents and their read times. */
37
- private ImmutableSortedMap <DocumentKey , Pair < MutableDocument , SnapshotVersion > > docs ;
36
+ private ImmutableSortedMap <DocumentKey , MutableDocument > docs ;
38
37
/** Manages the collection group index. */
39
38
private IndexManager indexManager ;
40
39
/** The latest read time of any document in the cache. */
@@ -56,7 +55,7 @@ public void add(MutableDocument document, SnapshotVersion readTime) {
56
55
hardAssert (
57
56
!readTime .equals (SnapshotVersion .NONE ),
58
57
"Cannot add document to the RemoteDocumentCache with a read time of zero" );
59
- docs = docs .insert (document .getKey (), new Pair <>( document .clone (), readTime ));
58
+ docs = docs .insert (document .getKey (), document .clone (). withReadTime ( readTime ));
60
59
latestReadTime = readTime .compareTo (latestReadTime ) > 0 ? readTime : latestReadTime ;
61
60
62
61
indexManager .addToCollectionParentIndex (document .getKey ().getPath ().popLast ());
@@ -69,8 +68,8 @@ public void remove(DocumentKey key) {
69
68
70
69
@ Override
71
70
public MutableDocument get (DocumentKey key ) {
72
- Pair < MutableDocument , SnapshotVersion > entry = docs .get (key );
73
- return entry != null ? entry . first .clone () : MutableDocument .newInvalidDocument (key );
71
+ MutableDocument doc = docs .get (key );
72
+ return doc != null ? doc .clone () : MutableDocument .newInvalidDocument (key );
74
73
}
75
74
76
75
@ Override
@@ -94,24 +93,22 @@ public ImmutableSortedMap<DocumentKey, MutableDocument> getAllDocumentsMatchingQ
94
93
// we need to match the query against.
95
94
ResourcePath queryPath = query .getPath ();
96
95
DocumentKey prefix = DocumentKey .fromPath (queryPath .append ("" ));
97
- Iterator <Map .Entry <DocumentKey , Pair <MutableDocument , SnapshotVersion >>> iterator =
98
- docs .iteratorFrom (prefix );
96
+ Iterator <Map .Entry <DocumentKey , MutableDocument >> iterator = docs .iteratorFrom (prefix );
99
97
100
98
while (iterator .hasNext ()) {
101
- Map .Entry <DocumentKey , Pair < MutableDocument , SnapshotVersion > > entry = iterator .next ();
99
+ Map .Entry <DocumentKey , MutableDocument > entry = iterator .next ();
102
100
103
101
DocumentKey key = entry .getKey ();
104
102
if (!queryPath .isPrefixOf (key .getPath ())) {
105
103
break ;
106
104
}
107
105
108
- MutableDocument doc = entry .getValue (). first ;
106
+ MutableDocument doc = entry .getValue ();
109
107
if (!doc .isFoundDocument ()) {
110
108
continue ;
111
109
}
112
110
113
- SnapshotVersion readTime = entry .getValue ().second ;
114
- if (IndexOffset .create (readTime , doc .getKey ()).compareTo (offset ) <= 0 ) {
111
+ if (IndexOffset .create (doc .getReadTime (), doc .getKey ()).compareTo (offset ) <= 0 ) {
115
112
continue ;
116
113
}
117
114
@@ -149,7 +146,7 @@ private class DocumentIterable implements Iterable<MutableDocument> {
149
146
@ NonNull
150
147
@ Override
151
148
public Iterator <MutableDocument > iterator () {
152
- Iterator <Map .Entry <DocumentKey , Pair < MutableDocument , SnapshotVersion > >> iterator =
149
+ Iterator <Map .Entry <DocumentKey , MutableDocument >> iterator =
153
150
MemoryRemoteDocumentCache .this .docs .iterator ();
154
151
return new Iterator <MutableDocument >() {
155
152
@ Override
@@ -159,7 +156,7 @@ public boolean hasNext() {
159
156
160
157
@ Override
161
158
public MutableDocument next () {
162
- return iterator .next ().getValue (). first ;
159
+ return iterator .next ().getValue ();
163
160
}
164
161
};
165
162
}
0 commit comments