@@ -152,14 +152,12 @@ public MutableDocument get(DocumentKey documentKey) {
152152 public Map <DocumentKey , MutableDocument > getAll (Iterable <DocumentKey > documentKeys ) {
153153 Map <DocumentKey , MutableDocument > results = new HashMap <>();
154154 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 ()));
158157
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 ));
163161 }
164162
165163 SQLitePersistence .LongQuery longQuery =
@@ -181,6 +179,7 @@ public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKe
181179
182180 documentTypeBackfills .backfill (db );
183181
182+ // Synchronize on `results` to avoid a data race with the background queue.
184183 synchronized (results ) {
185184 return results ;
186185 }
@@ -280,6 +279,7 @@ private Map<DocumentKey, MutableDocument> getAll(
280279
281280 documentTypeBackfills .backfill (db );
282281
282+ // Synchronize on `results` to avoid a data race with the background queue.
283283 synchronized (results ) {
284284 return results ;
285285 }
@@ -358,8 +358,25 @@ private MutableDocument decodeMaybeDocument(
358358 }
359359 }
360360
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+ */
363380 private static class DocumentTypeBackfills {
364381
365382 private final ConcurrentHashMap <BackfillKey , DocumentType > documentTypeByBackfillKey =
0 commit comments