Skip to content

Commit 264dd8a

Browse files
Review
1 parent b9d0318 commit 264dd8a

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleListener.java renamed to firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleCallback.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import com.google.firebase.firestore.model.DocumentKey;
2020
import com.google.firebase.firestore.model.MaybeDocument;
2121

22-
/** Interface implemented by components that can apply changes from a bundle. */
23-
public interface BundleListener {
22+
/** Interface implemented by components that can apply changes from a bundle to local storage. */
23+
public interface BundleCallback {
2424
/**
2525
* Applies the documents from a bundle to the "ground-state" (remote) documents.
2626
*

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleLoader.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* update while loading.
3535
*/
3636
public class BundleLoader {
37-
private final BundleListener bundleListener;
37+
private final BundleCallback bundleCallback;
3838
private final BundleMetadata bundleMetadata;
3939
private final int totalDocuments;
4040
private final long totalBytes;
@@ -46,11 +46,11 @@ public class BundleLoader {
4646
@Nullable private DocumentKey currentDocument;
4747

4848
public BundleLoader(
49-
BundleListener bundleListener,
49+
BundleCallback bundleCallback,
5050
BundleMetadata bundleMetadata,
5151
int totalDocuments,
5252
long totalBytes) {
53-
this.bundleListener = bundleListener;
53+
this.bundleCallback = bundleCallback;
5454
this.bundleMetadata = bundleMetadata;
5555
this.totalDocuments = totalDocuments;
5656
this.totalBytes = totalBytes;
@@ -69,7 +69,7 @@ public BundleLoader(
6969
Preconditions.checkArgument(
7070
!(bundleElement instanceof BundleMetadata), "Unexpected bundle metadata element.");
7171

72-
boolean updateProgress = false;
72+
int beforeDocumentCount = documents.size();
7373

7474
if (bundleElement instanceof NamedQuery) {
7575
queries.add((NamedQuery) bundleElement);
@@ -85,7 +85,6 @@ public BundleLoader(
8585
bundledDocumentMetadata.getKey(),
8686
bundledDocumentMetadata.getReadTime(),
8787
/* hasCommittedMutations= */ false));
88-
updateProgress = true;
8988
currentDocument = null;
9089
}
9190
} else if (bundleElement instanceof BundleDocument) {
@@ -95,13 +94,12 @@ public BundleLoader(
9594
"The document being added does not match the stored metadata.");
9695
}
9796
documents = documents.insert(bundleDocument.getKey(), bundleDocument.getDocument());
98-
updateProgress = true;
9997
currentDocument = null;
10098
}
10199

102100
bytesLoaded += byteSize;
103101

104-
return updateProgress
102+
return beforeDocumentCount != documents.size()
105103
? new LoadBundleTaskProgress(
106104
documents.size(),
107105
totalDocuments,
@@ -125,14 +123,14 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyChanges() {
125123
documents.size());
126124

127125
ImmutableSortedMap<DocumentKey, MaybeDocument> changes =
128-
bundleListener.applyBundledDocuments(documents, bundleMetadata.getBundleId());
126+
bundleCallback.applyBundledDocuments(documents, bundleMetadata.getBundleId());
129127

130128
Map<String, ImmutableSortedSet<DocumentKey>> queryDocumentMap = getQueryDocumentMapping();
131129
for (NamedQuery namedQuery : queries) {
132-
bundleListener.saveNamedQuery(namedQuery, queryDocumentMap.get(namedQuery.getName()));
130+
bundleCallback.saveNamedQuery(namedQuery, queryDocumentMap.get(namedQuery.getName()));
133131
}
134132

135-
bundleListener.saveBundle(bundleMetadata);
133+
bundleCallback.saveBundle(bundleMetadata);
136134

137135
return changes;
138136
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.google.firebase.database.collection.ImmutableSortedMap;
2525
import com.google.firebase.database.collection.ImmutableSortedSet;
2626
import com.google.firebase.firestore.auth.User;
27-
import com.google.firebase.firestore.bundle.BundleListener;
27+
import com.google.firebase.firestore.bundle.BundleCallback;
2828
import com.google.firebase.firestore.bundle.BundleMetadata;
2929
import com.google.firebase.firestore.bundle.NamedQuery;
3030
import com.google.firebase.firestore.core.Query;
@@ -95,7 +95,7 @@
9595
* <p>The LocalStore must be able to efficiently execute queries against its local cache of the
9696
* documents, to provide the initial set of results before any remote changes have been received.
9797
*/
98-
public final class LocalStore implements BundleListener {
98+
public final class LocalStore implements BundleCallback {
9999
/**
100100
* The maximum time to leave a resume token buffered without writing it out. This value is
101101
* arbitrary: it's long enough to avoid several writes (possibly indefinitely if updates come more

firebase-firestore/src/test/java/com/google/firebase/firestore/bundle/BundleLoaderTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public class BundleLoaderTest {
4949
public static final BundleMetadata BUNDLE_METADATA =
5050
new BundleMetadata("bundle-1", /* schemaVersion= */ 1, new SnapshotVersion(Timestamp.now()));
51-
private final BundleListener bundleListener;
51+
private final BundleCallback bundleCallback;
5252

5353
private final Set<DocumentKey> lastDocuments;
5454
private final Map<String, ImmutableSortedSet<DocumentKey>> lastQueries;
@@ -59,8 +59,8 @@ public BundleLoaderTest() {
5959
lastQueries = new HashMap<>();
6060
lastBundles = new HashMap<>();
6161

62-
bundleListener =
63-
new BundleListener() {
62+
bundleCallback =
63+
new BundleCallback() {
6464

6565
@Override
6666
public ImmutableSortedMap<DocumentKey, MaybeDocument> applyBundledDocuments(
@@ -93,7 +93,7 @@ public void before() {
9393
public void testLoadsDocuments() {
9494
BundleLoader bundleLoader =
9595
new BundleLoader(
96-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 10);
96+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 10);
9797

9898
LoadBundleTaskProgress progress =
9999
bundleLoader.addElement(
@@ -138,7 +138,7 @@ public void testLoadsDocuments() {
138138
public void testLoadsDeletedDocuments() {
139139
BundleLoader bundleLoader =
140140
new BundleLoader(
141-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 10);
141+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 10);
142142

143143
LoadBundleTaskProgress progress =
144144
bundleLoader.addElement(
@@ -160,7 +160,7 @@ public void testLoadsDeletedDocuments() {
160160
public void testAppliesDocumentChanges() {
161161
BundleLoader bundleLoader =
162162
new BundleLoader(
163-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
163+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
164164

165165
bundleLoader.addElement(
166166
new BundledDocumentMetadata(
@@ -181,7 +181,7 @@ public void testAppliesDocumentChanges() {
181181
public void testAppliesNamedQueries() {
182182
BundleLoader bundleLoader =
183183
new BundleLoader(
184-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 4);
184+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 4);
185185

186186
bundleLoader.addElement(
187187
new BundledDocumentMetadata(
@@ -220,7 +220,7 @@ public void testAppliesNamedQueries() {
220220
public void testVerifiesBundledDocumentMetadataSent() {
221221
BundleLoader bundleLoader =
222222
new BundleLoader(
223-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
223+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
224224
try {
225225
bundleLoader.addElement(new BundleDocument(doc("coll/doc1", 1, map())), /* byteSize= */ 5);
226226
fail();
@@ -233,7 +233,7 @@ public void testVerifiesBundledDocumentMetadataSent() {
233233
public void testVerifiesBundledDocumentMetadataMatches() {
234234
BundleLoader bundleLoader =
235235
new BundleLoader(
236-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
236+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 1, /* totalBytes= */ 5);
237237

238238
bundleLoader.addElement(
239239
new BundledDocumentMetadata(
@@ -255,7 +255,7 @@ public void testVerifiesBundledDocumentMetadataMatches() {
255255
public void testVerifiesDocumentFollowsMetadata() {
256256
BundleLoader bundleLoader =
257257
new BundleLoader(
258-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 0, /* totalBytes= */ 10);
258+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 0, /* totalBytes= */ 10);
259259

260260
bundleLoader.addElement(
261261
new BundledDocumentMetadata(
@@ -279,7 +279,7 @@ public void testVerifiesDocumentFollowsMetadata() {
279279
public void testVerifiesDocumentCount() {
280280
BundleLoader bundleLoader =
281281
new BundleLoader(
282-
bundleListener, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 10);
282+
bundleCallback, BUNDLE_METADATA, /* totalDocuments= */ 2, /* totalBytes= */ 10);
283283

284284
bundleLoader.addElement(
285285
new BundledDocumentMetadata(

0 commit comments

Comments
 (0)