Skip to content

Commit e5c8512

Browse files
Merge
2 parents 11936cc + 264dd8a commit e5c8512

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
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 List<NamedQuery> queries;
4040
private final Map<DocumentKey, BundledDocumentMetadata> documentsMetadata;
@@ -43,8 +43,8 @@ public class BundleLoader {
4343
private long bytesLoaded;
4444
@Nullable private DocumentKey currentDocument;
4545

46-
public BundleLoader(BundleListener bundleListener, BundleMetadata bundleMetadata) {
47-
this.bundleListener = bundleListener;
46+
public BundleLoader(BundleCallback bundleCallback, BundleMetadata bundleMetadata) {
47+
this.bundleCallback = bundleCallback;
4848
this.bundleMetadata = bundleMetadata;
4949
this.queries = new ArrayList<>();
5050
this.documents = emptyMaybeDocumentMap();
@@ -61,7 +61,7 @@ public BundleLoader(BundleListener bundleListener, BundleMetadata bundleMetadata
6161
Preconditions.checkArgument(
6262
!(bundleElement instanceof BundleMetadata), "Unexpected bundle metadata element.");
6363

64-
boolean updateProgress = false;
64+
int beforeDocumentCount = documents.size();
6565

6666
if (bundleElement instanceof NamedQuery) {
6767
queries.add((NamedQuery) bundleElement);
@@ -77,7 +77,6 @@ public BundleLoader(BundleListener bundleListener, BundleMetadata bundleMetadata
7777
bundledDocumentMetadata.getKey(),
7878
bundledDocumentMetadata.getReadTime(),
7979
/* hasCommittedMutations= */ false));
80-
updateProgress = true;
8180
currentDocument = null;
8281
}
8382
} else if (bundleElement instanceof BundleDocument) {
@@ -87,13 +86,12 @@ public BundleLoader(BundleListener bundleListener, BundleMetadata bundleMetadata
8786
"The document being added does not match the stored metadata.");
8887
}
8988
documents = documents.insert(bundleDocument.getKey(), bundleDocument.getDocument());
90-
updateProgress = true;
9189
currentDocument = null;
9290
}
9391

9492
bytesLoaded += byteSize;
9593

96-
return updateProgress
94+
return beforeDocumentCount != documents.size()
9795
? new LoadBundleTaskProgress(
9896
documents.size(),
9997
bundleMetadata.getTotalDocuments(),
@@ -117,14 +115,14 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyChanges() {
117115
documents.size());
118116

119117
ImmutableSortedMap<DocumentKey, MaybeDocument> changes =
120-
bundleListener.applyBundledDocuments(documents, bundleMetadata.getBundleId());
118+
bundleCallback.applyBundledDocuments(documents, bundleMetadata.getBundleId());
121119

122120
Map<String, ImmutableSortedSet<DocumentKey>> queryDocumentMap = getQueryDocumentMapping();
123121
for (NamedQuery namedQuery : queries) {
124-
bundleListener.saveNamedQuery(namedQuery, queryDocumentMap.get(namedQuery.getName()));
122+
bundleCallback.saveNamedQuery(namedQuery, queryDocumentMap.get(namedQuery.getName()));
125123
}
126124

127-
bundleListener.saveBundle(bundleMetadata);
125+
bundleCallback.saveBundle(bundleMetadata);
128126

129127
return changes;
130128
}

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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public class BundleLoaderTest {
4949
private static final SnapshotVersion CREATE_TIME = new SnapshotVersion(Timestamp.now());
5050

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(
@@ -92,7 +92,7 @@ public void before() {
9292
@Test
9393
public void testLoadsDocuments() {
9494
BundleLoader bundleLoader =
95-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 2));
95+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 2));
9696

9797
LoadBundleTaskProgress progress =
9898
bundleLoader.addElement(
@@ -130,7 +130,7 @@ public void testLoadsDocuments() {
130130
@Test
131131
public void testLoadsDeletedDocuments() {
132132
BundleLoader bundleLoader =
133-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 1));
133+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 1));
134134

135135
LoadBundleTaskProgress progress =
136136
bundleLoader.addElement(
@@ -148,7 +148,7 @@ public void testLoadsDeletedDocuments() {
148148
@Test
149149
public void testAppliesDocumentChanges() {
150150
BundleLoader bundleLoader =
151-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 1));
151+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 1));
152152

153153
bundleLoader.addElement(
154154
new BundledDocumentMetadata(
@@ -165,7 +165,7 @@ public void testAppliesDocumentChanges() {
165165
@Test
166166
public void testAppliesNamedQueries() {
167167
BundleLoader bundleLoader =
168-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 2));
168+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 2));
169169

170170
bundleLoader.addElement(
171171
new BundledDocumentMetadata(
@@ -203,7 +203,7 @@ public void testAppliesNamedQueries() {
203203
@Test
204204
public void testVerifiesBundledDocumentMetadataSent() {
205205
BundleLoader bundleLoader =
206-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 1));
206+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 1));
207207

208208
try {
209209
bundleLoader.addElement(new BundleDocument(doc("coll/doc1", 1, map())), /* byteSize= */ 10);
@@ -216,8 +216,7 @@ public void testVerifiesBundledDocumentMetadataSent() {
216216
@Test
217217
public void testVerifiesBundledDocumentMetadataMatches() {
218218
BundleLoader bundleLoader =
219-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 1));
220-
219+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 1));
221220
bundleLoader.addElement(
222221
new BundledDocumentMetadata(
223222
key("coll/doc1"), CREATE_TIME, /* exists= */ true, Collections.emptyList()),
@@ -234,7 +233,7 @@ public void testVerifiesBundledDocumentMetadataMatches() {
234233
@Test
235234
public void testVerifiesDocumentFollowsMetadata() {
236235
BundleLoader bundleLoader =
237-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 0));
236+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 0));
238237

239238
bundleLoader.addElement(
240239
new BundledDocumentMetadata(
@@ -254,7 +253,7 @@ public void testVerifiesDocumentFollowsMetadata() {
254253
@Test
255254
public void testVerifiesDocumentCount() {
256255
BundleLoader bundleLoader =
257-
new BundleLoader(bundleListener, createMetadata(/* documents= */ 2));
256+
new BundleLoader(bundleCallback, createMetadata(/* documents= */ 2));
258257

259258
bundleLoader.addElement(
260259
new BundledDocumentMetadata(

0 commit comments

Comments
 (0)