use of com.google.firebase.firestore.model.mutation.Overlay in project firebase-android-sdk by firebase.
the class SQLiteDocumentOverlayCache method getOverlays.
@Override
public Map<DocumentKey, Overlay> getOverlays(ResourcePath collection, int sinceBatchId) {
Map<DocumentKey, Overlay> result = new HashMap<>();
BackgroundQueue backgroundQueue = new BackgroundQueue();
db.query("SELECT overlay_mutation, largest_batch_id FROM document_overlays " + "WHERE uid = ? AND collection_path = ? AND largest_batch_id > ?").binding(uid, EncodedPath.encode(collection), sinceBatchId).forEach(row -> processOverlaysInBackground(backgroundQueue, result, row));
backgroundQueue.drain();
return result;
}
use of com.google.firebase.firestore.model.mutation.Overlay in project firebase-android-sdk by firebase.
the class SQLiteDocumentOverlayCache method getOverlays.
@Override
public Map<DocumentKey, Overlay> getOverlays(String collectionGroup, int sinceBatchId, int count) {
Map<DocumentKey, Overlay> result = new HashMap<>();
String[] lastCollectionPath = new String[1];
String[] lastDocumentPath = new String[1];
int[] lastLargestBatchId = new int[1];
BackgroundQueue backgroundQueue = new BackgroundQueue();
db.query("SELECT overlay_mutation, largest_batch_id, collection_path, document_id " + " FROM document_overlays " + "WHERE uid = ? AND collection_group = ? AND largest_batch_id > ? " + "ORDER BY largest_batch_id, collection_path, document_id LIMIT ?").binding(uid, collectionGroup, sinceBatchId, count).forEach(row -> {
lastLargestBatchId[0] = row.getInt(1);
lastCollectionPath[0] = row.getString(2);
lastDocumentPath[0] = row.getString(3);
processOverlaysInBackground(backgroundQueue, result, row);
});
if (lastCollectionPath[0] == null) {
return result;
}
// This function should not return partial batch overlays, even if the number of overlays in the
// result set exceeds the given `count` argument. Since the `LIMIT` in the above query might
// result in a partial batch, the following query appends any remaining overlays for the last
// batch.
db.query("SELECT overlay_mutation, largest_batch_id FROM document_overlays " + "WHERE uid = ? AND collection_group = ? " + "AND (collection_path > ? OR (collection_path = ? AND document_id > ?)) " + "AND largest_batch_id = ?").binding(uid, collectionGroup, lastCollectionPath[0], lastCollectionPath[0], lastDocumentPath[0], lastLargestBatchId[0]).forEach(row -> processOverlaysInBackground(backgroundQueue, result, row));
backgroundQueue.drain();
return result;
}
use of com.google.firebase.firestore.model.mutation.Overlay in project firebase-android-sdk by firebase.
the class SQLiteDocumentOverlayCache method getOverlays.
@Override
public Map<DocumentKey, Overlay> getOverlays(SortedSet<DocumentKey> keys) {
hardAssert(keys.comparator() == null, "getOverlays() requires natural order");
Map<DocumentKey, Overlay> result = new HashMap<>();
BackgroundQueue backgroundQueue = new BackgroundQueue();
ResourcePath currentCollection = ResourcePath.EMPTY;
List<Object> accumulatedDocumentIds = new ArrayList<>();
for (DocumentKey key : keys) {
if (!currentCollection.equals(key.getCollectionPath())) {
processSingleCollection(result, backgroundQueue, currentCollection, accumulatedDocumentIds);
currentCollection = key.getCollectionPath();
accumulatedDocumentIds.clear();
}
accumulatedDocumentIds.add(key.getDocumentId());
}
processSingleCollection(result, backgroundQueue, currentCollection, accumulatedDocumentIds);
backgroundQueue.drain();
return result;
}
use of com.google.firebase.firestore.model.mutation.Overlay in project firebase-android-sdk by firebase.
the class SQLiteDocumentOverlayCache method processOverlaysInBackground.
private void processOverlaysInBackground(BackgroundQueue backgroundQueue, Map<DocumentKey, Overlay> results, Cursor row) {
byte[] rawMutation = row.getBlob(0);
int largestBatchId = row.getInt(1);
// Since scheduling background tasks incurs overhead, we only dispatch to a
// background thread if there are still some documents remaining.
Executor executor = row.isLast() ? Executors.DIRECT_EXECUTOR : backgroundQueue;
executor.execute(() -> {
Overlay overlay = decodeOverlay(rawMutation, largestBatchId);
synchronized (results) {
results.put(overlay.getKey(), overlay);
}
});
}
use of com.google.firebase.firestore.model.mutation.Overlay in project firebase-android-sdk by firebase.
the class LocalDocumentsView method getDocument.
/**
* Returns the the local view of the document identified by {@code key}.
*
* @return Local view of the document or a an invalid document if we don't have any cached state
* for it.
*/
Document getDocument(DocumentKey key) {
Overlay overlay = documentOverlayCache.getOverlay(key);
MutableDocument document = getBaseDocument(key, overlay);
if (overlay != null) {
overlay.getMutation().applyToLocalView(document, null, Timestamp.now());
}
return document;
}
Aggregations