use of com.google.firebase.firestore.model.Document in project firebase-android-sdk by firebase.
the class SQLiteRemoteDocumentCache method removeAll.
@Override
public void removeAll(Collection<DocumentKey> keys) {
if (keys.isEmpty())
return;
List<Object> encodedPaths = new ArrayList<>();
ImmutableSortedMap<DocumentKey, Document> deletedDocs = emptyDocumentMap();
for (DocumentKey key : keys) {
encodedPaths.add(EncodedPath.encode(key.getPath()));
deletedDocs = deletedDocs.insert(key, MutableDocument.newNoDocument(key, SnapshotVersion.NONE));
}
SQLitePersistence.LongQuery longQuery = new SQLitePersistence.LongQuery(db, "DELETE FROM remote_documents WHERE path IN (", encodedPaths, ")");
while (longQuery.hasMoreSubqueries()) {
longQuery.executeNextSubquery();
}
indexManager.updateIndexEntries(deletedDocs);
}
use of com.google.firebase.firestore.model.Document in project firebase-android-sdk by firebase.
the class LocalStore method executeQuery.
/**
* Runs the specified query against the local store and returns the results, potentially taking
* advantage of query data from previous executions (such as the set of remote keys).
*
* @param usePreviousResults Whether results from previous executions can be used to optimize this
* query execution.
*/
public QueryResult executeQuery(Query query, boolean usePreviousResults) {
TargetData targetData = getTargetData(query.toTarget());
SnapshotVersion lastLimboFreeSnapshotVersion = SnapshotVersion.NONE;
ImmutableSortedSet<DocumentKey> remoteKeys = DocumentKey.emptyKeySet();
if (targetData != null) {
lastLimboFreeSnapshotVersion = targetData.getLastLimboFreeSnapshotVersion();
remoteKeys = this.targetCache.getMatchingKeysForTargetId(targetData.getTargetId());
}
ImmutableSortedMap<DocumentKey, Document> documents = queryEngine.getDocumentsMatchingQuery(query, usePreviousResults ? lastLimboFreeSnapshotVersion : SnapshotVersion.NONE, remoteKeys);
return new QueryResult(documents, remoteKeys);
}
use of com.google.firebase.firestore.model.Document in project firebase-android-sdk by firebase.
the class LocalDocumentsView method computeViews.
/*Computes the local view for doc */
private ImmutableSortedMap<DocumentKey, Document> computeViews(Map<DocumentKey, MutableDocument> docs, Map<DocumentKey, Overlay> overlays, Set<DocumentKey> existenceStateChanged) {
ImmutableSortedMap<DocumentKey, Document> results = emptyDocumentMap();
Map<DocumentKey, MutableDocument> recalculateDocuments = new HashMap<>();
for (MutableDocument doc : docs.values()) {
Overlay overlay = overlays.get(doc.getKey());
// but would now match.
if (existenceStateChanged.contains(doc.getKey()) && (overlay == null || overlay.getMutation() instanceof PatchMutation)) {
recalculateDocuments.put(doc.getKey(), doc);
} else if (overlay != null) {
overlay.getMutation().applyToLocalView(doc, null, Timestamp.now());
}
}
recalculateAndSaveOverlays(recalculateDocuments);
for (Map.Entry<DocumentKey, MutableDocument> entry : docs.entrySet()) {
results = results.insert(entry.getKey(), entry.getValue());
}
return results;
}
use of com.google.firebase.firestore.model.Document in project firebase-android-sdk by firebase.
the class LocalDocumentsView method getDocumentsMatchingCollectionQuery.
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollectionQuery(Query query, IndexOffset offset) {
Map<DocumentKey, MutableDocument> remoteDocuments = remoteDocumentCache.getAll(query.getPath(), offset);
Map<DocumentKey, Overlay> overlays = documentOverlayCache.getOverlays(query.getPath(), offset.getLargestBatchId());
// for all overlays in the initial document set.
for (Map.Entry<DocumentKey, Overlay> entry : overlays.entrySet()) {
if (!remoteDocuments.containsKey(entry.getKey())) {
remoteDocuments.put(entry.getKey(), MutableDocument.newInvalidDocument(entry.getKey()));
}
}
// Apply the overlays and match against the query.
ImmutableSortedMap<DocumentKey, Document> results = emptyDocumentMap();
for (Map.Entry<DocumentKey, MutableDocument> docEntry : remoteDocuments.entrySet()) {
Overlay overlay = overlays.get(docEntry.getKey());
if (overlay != null) {
overlay.getMutation().applyToLocalView(docEntry.getValue(), null, Timestamp.now());
}
// Finally, insert the documents that still match the query
if (query.matches(docEntry.getValue())) {
results = results.insert(docEntry.getKey(), docEntry.getValue());
}
}
return results;
}
Aggregations