@@ -152,14 +152,12 @@ public MutableDocument get(DocumentKey documentKey) {
152
152
public Map <DocumentKey , MutableDocument > getAll (Iterable <DocumentKey > documentKeys ) {
153
153
Map <DocumentKey , MutableDocument > results = new HashMap <>();
154
154
List <Object > bindVars = new ArrayList <>();
155
- synchronized (results ) {
156
- for (DocumentKey key : documentKeys ) {
157
- bindVars .add (EncodedPath .encode (key .getPath ()));
155
+ for (DocumentKey key : documentKeys ) {
156
+ bindVars .add (EncodedPath .encode (key .getPath ()));
158
157
159
- // Make sure each key has a corresponding entry, which is null in case the document is not
160
- // found.
161
- results .put (key , MutableDocument .newInvalidDocument (key ));
162
- }
158
+ // Make sure each key has a corresponding entry, which is null in case the document is not
159
+ // found.
160
+ results .put (key , MutableDocument .newInvalidDocument (key ));
163
161
}
164
162
165
163
SQLitePersistence .LongQuery longQuery =
@@ -181,6 +179,7 @@ public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKe
181
179
182
180
documentTypeBackfills .backfill (db );
183
181
182
+ // Synchronize on `results` to avoid a data race with the background queue.
184
183
synchronized (results ) {
185
184
return results ;
186
185
}
@@ -280,6 +279,7 @@ private Map<DocumentKey, MutableDocument> getAll(
280
279
281
280
documentTypeBackfills .backfill (db );
282
281
282
+ // Synchronize on `results` to avoid a data race with the background queue.
283
283
synchronized (results ) {
284
284
return results ;
285
285
}
@@ -358,8 +358,25 @@ private MutableDocument decodeMaybeDocument(
358
358
}
359
359
}
360
360
361
- // This class is thread safe and all public methods may be safely called concurrently from
362
- // multiple threads. This makes it safe to use instances of this class from BackgroundQueue.
361
+ /**
362
+ * Helper class to backfill the `document_type` column in the `remote_documents` table.
363
+ * <p>
364
+ * The `document_type` column was added as an optimization to skip deleted document tombstones
365
+ * when running queries. Any time a new row is added to the `remote_documents` table it _should_
366
+ * have its `document_type` column set to the value that matches the `contents` field. However,
367
+ * when upgrading from an older schema version the column value for existing rows will be null
368
+ * and this backfiller is intended to replace those null values to improve the future performance
369
+ * of queries.
370
+ * <p>
371
+ * When traversing the `remote_documents` table call `add()` upon finding a row whose
372
+ * `document_type` is null. Then, call `backfill()` later on to efficiently update the added
373
+ * rows in batches.
374
+ * <p>
375
+ * This class is thread safe and all public methods may be safely called concurrently from
376
+ * multiple threads. This makes it safe to use instances of this class from BackgroundQueue.
377
+ *
378
+ * @see <a href="https://github.com/firebase/firebase-android-sdk/issues/7295">#7295</a>
379
+ */
363
380
private static class DocumentTypeBackfills {
364
381
365
382
private final ConcurrentHashMap <BackfillKey , DocumentType > documentTypeByBackfillKey =
0 commit comments