use of com.google.firebase.firestore.model.FieldIndex.IndexOffset in project firebase-android-sdk by firebase.
the class IndexBackfiller method writeEntriesForCollectionGroup.
/**
* Writes entries for the provided collection group. Returns the number of documents processed.
*/
private int writeEntriesForCollectionGroup(String collectionGroup, int documentsRemainingUnderCap) {
// Use the earliest offset of all field indexes to query the local cache.
IndexOffset existingOffset = indexManager.getMinOffset(collectionGroup);
LocalDocumentsResult nextBatch = localDocumentsView.getNextDocuments(collectionGroup, existingOffset, documentsRemainingUnderCap);
indexManager.updateIndexEntries(nextBatch.getDocuments());
IndexOffset newOffset = getNewOffset(existingOffset, nextBatch);
Logger.debug(LOG_TAG, "Updating offset: %s", newOffset);
indexManager.updateCollectionGroup(collectionGroup, newOffset);
return nextBatch.getDocuments().size();
}
use of com.google.firebase.firestore.model.FieldIndex.IndexOffset in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method getMinOffset.
private IndexOffset getMinOffset(Collection<FieldIndex> fieldIndexes) {
hardAssert(!fieldIndexes.isEmpty(), "Found empty index group when looking for least recent index offset.");
Iterator<FieldIndex> it = fieldIndexes.iterator();
IndexOffset minOffset = it.next().getIndexState().getOffset();
int minBatchId = minOffset.getLargestBatchId();
while (it.hasNext()) {
IndexOffset newOffset = it.next().getIndexState().getOffset();
if (newOffset.compareTo(minOffset) < 0) {
minOffset = newOffset;
}
minBatchId = Math.max(newOffset.getLargestBatchId(), minBatchId);
}
return IndexOffset.create(minOffset.getReadTime(), minOffset.getDocumentKey(), minBatchId);
}
use of com.google.firebase.firestore.model.FieldIndex.IndexOffset in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testPersistsIndexOffset.
@Test
public void testPersistsIndexOffset() {
indexManager.addFieldIndex(fieldIndex("coll1", "value", Kind.ASCENDING));
IndexOffset offset = IndexOffset.create(version(20), key("coll/doc"), 42);
indexManager.updateCollectionGroup("coll1", offset);
indexManager = persistence.getIndexManager(User.UNAUTHENTICATED);
indexManager.start();
Collection<FieldIndex> indexes = indexManager.getFieldIndexes("coll1");
assertEquals(indexes.size(), 1);
FieldIndex index = indexes.iterator().next();
assertEquals(offset, index.getIndexState().getOffset());
}
use of com.google.firebase.firestore.model.FieldIndex.IndexOffset in project firebase-android-sdk by firebase.
the class CountingQueryEngine method wrapRemoteDocumentCache.
private RemoteDocumentCache wrapRemoteDocumentCache(RemoteDocumentCache subject) {
return new RemoteDocumentCache() {
@Override
public void setIndexManager(IndexManager indexManager) {
// Not implemented.
}
@Override
public void add(MutableDocument document, SnapshotVersion readTime) {
subject.add(document, readTime);
}
@Override
public void removeAll(Collection<DocumentKey> keys) {
subject.removeAll(keys);
}
@Override
public MutableDocument get(DocumentKey documentKey) {
MutableDocument result = subject.get(documentKey);
documentsReadByKey[0] += result.isValidDocument() ? 1 : 0;
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKeys) {
Map<DocumentKey, MutableDocument> result = subject.getAll(documentKeys);
for (MutableDocument document : result.values()) {
documentsReadByKey[0] += document.isValidDocument() ? 1 : 0;
}
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(String collectionGroup, IndexOffset offset, int limit) {
Map<DocumentKey, MutableDocument> result = subject.getAll(collectionGroup, offset, limit);
documentsReadByCollection[0] += result.size();
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(ResourcePath collection, IndexOffset offset) {
Map<DocumentKey, MutableDocument> result = subject.getAll(collection, offset);
documentsReadByCollection[0] += result.size();
return result;
}
};
}
use of com.google.firebase.firestore.model.FieldIndex.IndexOffset in project firebase-android-sdk by firebase.
the class FieldIndexTest method indexOffsetComparator.
@Test
public void indexOffsetComparator() {
IndexOffset docAOffset = IndexOffset.create(version(1), key("foo/a"), -1);
IndexOffset docBOffset = IndexOffset.create(version(1), key("foo/b"), -1);
IndexOffset version1Offset = IndexOffset.createSuccessor(version(1), -1);
IndexOffset docCOffset = IndexOffset.create(version(2), key("foo/c"), -1);
IndexOffset version2Offset = IndexOffset.createSuccessor(version(2), -1);
assertEquals(-1, docAOffset.compareTo(docBOffset));
assertEquals(-1, docAOffset.compareTo(version1Offset));
assertEquals(-1, version1Offset.compareTo(docCOffset));
assertEquals(-1, version1Offset.compareTo(version2Offset));
assertEquals(-1, docCOffset.compareTo(version2Offset));
}
Aggregations