29
29
import com .google .firebase .firestore .remote .TargetChange ;
30
30
import java .util .ArrayList ;
31
31
import java .util .Collections ;
32
+ import java .util .Comparator ;
32
33
import java .util .List ;
33
34
import java .util .Map ;
34
35
@@ -156,6 +157,7 @@ public DocumentChanges computeDocChanges(
156
157
? oldDocumentSet .getFirstDocument ()
157
158
: null ;
158
159
160
+ Comparator <Document > queryComparator = query .comparator ();
159
161
for (Map .Entry <DocumentKey , Document > entry : docChanges ) {
160
162
DocumentKey key = entry .getKey ();
161
163
Document oldDoc = oldDocumentSet .getDocument (key );
@@ -182,9 +184,9 @@ public DocumentChanges computeDocChanges(
182
184
changeSet .addChange (DocumentViewChange .create (Type .MODIFIED , newDoc ));
183
185
changeApplied = true ;
184
186
185
- if ((lastDocInLimit != null && query . comparator () .compare (newDoc , lastDocInLimit ) > 0 )
187
+ if ((lastDocInLimit != null && queryComparator .compare (newDoc , lastDocInLimit ) > 0 )
186
188
|| (firstDocInLimit != null
187
- && query . comparator () .compare (newDoc , firstDocInLimit ) < 0 )) {
189
+ && queryComparator .compare (newDoc , firstDocInLimit ) < 0 )) {
188
190
// This doc moved from inside the limit to outside the limit. That means there may be
189
191
// some doc in the local cache that should be included instead.
190
192
needsRefill = true ;
@@ -296,15 +298,17 @@ public ViewChange applyChanges(
296
298
mutatedKeys = docChanges .mutatedKeys ;
297
299
298
300
// Sort changes based on type and query comparator.
301
+
299
302
List <DocumentViewChange > viewChanges = docChanges .changeSet .getChanges ();
303
+ Comparator <Document > queryComparator = query .comparator ();
300
304
Collections .sort (
301
305
viewChanges ,
302
306
(DocumentViewChange o1 , DocumentViewChange o2 ) -> {
303
307
int typeComp = Integer .compare (View .changeTypeOrder (o1 ), View .changeTypeOrder (o2 ));
304
308
if (typeComp != 0 ) {
305
309
return typeComp ;
306
310
}
307
- return query . comparator () .compare (o1 .getDocument (), o2 .getDocument ());
311
+ return queryComparator .compare (o1 .getDocument (), o2 .getDocument ());
308
312
});
309
313
applyTargetChange (targetChange );
310
314
List <LimboDocumentChange > limboDocumentChanges =
0 commit comments