Skip to content

Commit b2e7d05

Browse files
Merge
2 parents 71e366c + 567af79 commit b2e7d05

File tree

3 files changed

+40
-105
lines changed

3 files changed

+40
-105
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ DocumentOverlayCache getDocumentOverlayCache() {
7878
return documentOverlayCache;
7979
}
8080

81-
@VisibleForTesting
82-
IndexManager getIndexManager() {
83-
return indexManager;
84-
}
85-
8681
/**
8782
* Returns the the local view of the document identified by {@code key}.
8883
*

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

Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.firebase.firestore.local;
1616

1717
import androidx.annotation.Nullable;
18-
import com.google.firebase.Timestamp;
1918
import com.google.firebase.database.collection.ImmutableSortedMap;
2019
import com.google.firebase.database.collection.ImmutableSortedSet;
2120
import com.google.firebase.firestore.core.Query;
@@ -26,10 +25,8 @@
2625
import com.google.firebase.firestore.model.ResourcePath;
2726
import com.google.firebase.firestore.model.SnapshotVersion;
2827
import com.google.firebase.firestore.model.mutation.Mutation;
29-
import com.google.firebase.firestore.model.mutation.MutationBatch;
30-
import com.google.protobuf.ByteString;
28+
import com.google.firebase.firestore.model.mutation.Overlay;
3129
import java.util.Collection;
32-
import java.util.List;
3330
import java.util.Map;
3431

3532
/**
@@ -39,8 +36,6 @@
3936
class CountingQueryEngine extends QueryEngine {
4037
private final QueryEngine queryEngine;
4138

42-
private final int[] mutationsReadByCollection = new int[] {0};
43-
private final int[] mutationsReadByKey = new int[] {0};
4439
private final int[] overlaysReadByCollection = new int[] {0};
4540
private final int[] overlaysReadByKey = new int[] {0};
4641
private final int[] documentsReadByCollection = new int[] {0};
@@ -51,10 +46,8 @@ class CountingQueryEngine extends QueryEngine {
5146
}
5247

5348
void resetCounts() {
54-
mutationsReadByCollection[0] = 0;
55-
mutationsReadByKey[0] = 0;
5649
overlaysReadByCollection[0] = 0;
57-
mutationsReadByKey[0] = 0;
50+
overlaysReadByKey[0] = 0;
5851
documentsReadByCollection[0] = 0;
5952
documentsReadByKey[0] = 0;
6053
}
@@ -64,9 +57,9 @@ public void initialize(LocalDocumentsView localDocuments, IndexManager indexMana
6457
LocalDocumentsView wrappedView =
6558
new LocalDocumentsView(
6659
wrapRemoteDocumentCache(localDocuments.getRemoteDocumentCache()),
67-
wrapMutationQueue(localDocuments.getMutationQueue()),
68-
localDocuments.getDocumentOverlayCache(),
69-
localDocuments.getIndexManager());
60+
localDocuments.getMutationQueue(),
61+
wrapOverlayCache(localDocuments.getDocumentOverlayCache()),
62+
indexManager);
7063
queryEngine.initialize(wrappedView, indexManager);
7164
}
7265

@@ -78,6 +71,11 @@ public ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingQuery(
7871
return queryEngine.getDocumentsMatchingQuery(query, lastLimboFreeSnapshotVersion, remoteKeys);
7972
}
8073

74+
/** Returns the query engine that is used as the backing implementation. */
75+
QueryEngine getSubject() {
76+
return queryEngine;
77+
}
78+
8179
/**
8280
* Returns the number of documents returned by the RemoteDocumentCache's `getAll()` API (since the
8381
* last call to `resetCounts()`)
@@ -95,20 +93,19 @@ int getDocumentsReadByKey() {
9593
}
9694

9795
/**
98-
* Returns the number of mutations returned by the MutationQueue's
99-
* `getAllMutationBatchesAffectingQuery()` API (since the last call to `resetCounts()`)
96+
* Returns the number of mutations returned by the OverlayCache's `getOverlays()` API (since the
97+
* last call to `resetCounts()`)
10098
*/
101-
int getMutationsReadByCollection() {
102-
return mutationsReadByCollection[0];
99+
int getOverlaysReadByCollection() {
100+
return overlaysReadByCollection[0];
103101
}
104102

105103
/**
106-
* Returns the number of mutations returned by the MutationQueue's
107-
* `getAllMutationBatchesAffectingDocumentKey()` and
108-
* `getAllMutationBatchesAffectingDocumentKeys()` APIs (since the last call to `resetCounts()`)
104+
* Returns the number of mutations returned by the OverlayCache's `getOverlay()` API (since the
105+
* last call to `resetCounts()`)
109106
*/
110-
int getMutationsReadByKey() {
111-
return mutationsReadByKey[0];
107+
int getOverlaysReadByKey() {
108+
return overlaysReadByKey[0];
112109
}
113110

114111
private RemoteDocumentCache wrapRemoteDocumentCache(RemoteDocumentCache subject) {
@@ -167,96 +164,40 @@ public SnapshotVersion getLatestReadTime() {
167164
};
168165
}
169166

170-
private MutationQueue wrapMutationQueue(MutationQueue subject) {
171-
return new MutationQueue() {
172-
@Override
173-
public void start() {
174-
subject.start();
175-
}
176-
177-
@Override
178-
public boolean isEmpty() {
179-
return subject.isEmpty();
180-
}
181-
182-
@Override
183-
public void acknowledgeBatch(MutationBatch batch, ByteString streamToken) {
184-
subject.acknowledgeBatch(batch, streamToken);
185-
}
186-
187-
@Override
188-
public ByteString getLastStreamToken() {
189-
return subject.getLastStreamToken();
190-
}
191-
192-
@Override
193-
public void setLastStreamToken(ByteString streamToken) {
194-
subject.setLastStreamToken(streamToken);
195-
}
196-
197-
@Override
198-
public MutationBatch addMutationBatch(
199-
Timestamp localWriteTime, List<Mutation> baseMutations, List<Mutation> mutations) {
200-
return subject.addMutationBatch(localWriteTime, baseMutations, mutations);
201-
}
202-
167+
private DocumentOverlayCache wrapOverlayCache(DocumentOverlayCache subject) {
168+
return new DocumentOverlayCache() {
203169
@Nullable
204170
@Override
205-
public MutationBatch lookupMutationBatch(int batchId) {
206-
return subject.lookupMutationBatch(batchId);
207-
}
208-
209-
@Nullable
210-
@Override
211-
public MutationBatch getNextMutationBatchAfterBatchId(int batchId) {
212-
return subject.getNextMutationBatchAfterBatchId(batchId);
213-
}
214-
215-
@Override
216-
public int getHighestUnacknowledgedBatchId() {
217-
return subject.getHighestUnacknowledgedBatchId();
171+
public Overlay getOverlay(DocumentKey key) {
172+
++overlaysReadByKey[0];
173+
return subject.getOverlay(key);
218174
}
219175

220176
@Override
221-
public List<MutationBatch> getAllMutationBatches() {
222-
List<MutationBatch> result = subject.getAllMutationBatches();
223-
mutationsReadByKey[0] += result.size();
224-
return result;
177+
public void saveOverlays(int largestBatchId, Map<DocumentKey, Mutation> overlays) {
178+
subject.saveOverlays(largestBatchId, overlays);
225179
}
226180

227181
@Override
228-
public List<MutationBatch> getAllMutationBatchesAffectingDocumentKey(
229-
DocumentKey documentKey) {
230-
List<MutationBatch> result = subject.getAllMutationBatchesAffectingDocumentKey(documentKey);
231-
mutationsReadByKey[0] += result.size();
232-
return result;
182+
public void removeOverlaysForBatchId(int batchId) {
183+
subject.removeOverlaysForBatchId(batchId);
233184
}
234185

235186
@Override
236-
public List<MutationBatch> getAllMutationBatchesAffectingDocumentKeys(
237-
Iterable<DocumentKey> documentKeys) {
238-
List<MutationBatch> result =
239-
subject.getAllMutationBatchesAffectingDocumentKeys(documentKeys);
240-
mutationsReadByKey[0] += result.size();
187+
public Map<DocumentKey, Overlay> getOverlays(ResourcePath collection, int sinceBatchId) {
188+
Map<DocumentKey, Overlay> result = subject.getOverlays(collection, sinceBatchId);
189+
overlaysReadByCollection[0] += result.size();
241190
return result;
242191
}
243192

244193
@Override
245-
public List<MutationBatch> getAllMutationBatchesAffectingQuery(Query query) {
246-
List<MutationBatch> result = subject.getAllMutationBatchesAffectingQuery(query);
247-
mutationsReadByCollection[0] += result.size();
194+
public Map<DocumentKey, Overlay> getOverlays(
195+
String collectionGroup, int sinceBatchId, int count) {
196+
Map<DocumentKey, Overlay> result =
197+
subject.getOverlays(collectionGroup, sinceBatchId, count);
198+
overlaysReadByCollection[0] += result.size();
248199
return result;
249200
}
250-
251-
@Override
252-
public void removeMutationBatch(MutationBatch batch) {
253-
subject.removeMutationBatch(batch);
254-
}
255-
256-
@Override
257-
public void performConsistencyCheck() {
258-
subject.performConsistencyCheck();
259-
}
260201
};
261202
}
262203
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ private void assertHasNamedQuery(NamedQuery expectedNamedQuery) {
324324
}
325325

326326
/**
327-
* Asserts the expected numbers of mutations read by the MutationQueue since the last call to
327+
* Asserts the expected numbers of mutations read by the OverlayQueue since the last call to
328328
* `resetPersistenceStats()`.
329329
*/
330-
protected void assertMutationsRead(int byKey, int byCollection) {
330+
private void assertOverlaysRead(int byKey, int byCollection) {
331+
assertEquals("Overlays read (by key)", byKey, queryEngine.getOverlaysReadByKey());
331332
assertEquals(
332-
"Mutations read (by collection)", byCollection, queryEngine.getMutationsReadByCollection());
333-
assertEquals("Mutations read (by key)", byKey, queryEngine.getMutationsReadByKey());
333+
"Overlays read (by collection)", byCollection, queryEngine.getOverlaysReadByCollection());
334334
}
335335

336336
/**
@@ -975,8 +975,7 @@ public void testReadsAllDocumentsForInitialCollectionQueries() {
975975

976976
localStore.executeQuery(query, /* usePreviousResults= */ true);
977977
assertRemoteDocumentsRead(/* byKey= */ 0, /* byCollection= */ 2);
978-
// No mutations are read because only overlay is needed.
979-
assertMutationsRead(/* byKey= */ 0, /* byCollection= */ 0);
978+
assertOverlaysRead(/* byKey= */ 0, /* byCollection= */ 1);
980979
}
981980

982981
@Test

0 commit comments

Comments
 (0)