use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class MemoryEagerReferenceDelegate method onTransactionCommitted.
/**
* In eager garbage collection, collection is run on transaction commit.
*/
@Override
public void onTransactionCommitted() {
MemoryRemoteDocumentCache remoteDocuments = persistence.getRemoteDocumentCache();
List<DocumentKey> docsToRemove = new ArrayList<>();
for (DocumentKey key : orphanedDocuments) {
if (!isReferenced(key)) {
docsToRemove.add(key);
}
}
remoteDocuments.removeAll(docsToRemove);
orphanedDocuments = null;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class LocalSerializer method decodeUnknownDocument.
/**
* Decodes a UnknownDocument proto to the equivalent model.
*/
private MutableDocument decodeUnknownDocument(com.google.firebase.firestore.proto.UnknownDocument proto) {
DocumentKey key = rpcSerializer.decodeKey(proto.getName());
SnapshotVersion version = rpcSerializer.decodeVersion(proto.getVersion());
return MutableDocument.newUnknownDocument(key, version);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class LocalSerializer method decodeNoDocument.
/**
* Decodes a NoDocument proto to the equivalent model.
*/
private MutableDocument decodeNoDocument(com.google.firebase.firestore.proto.NoDocument proto, boolean hasCommittedMutations) {
DocumentKey key = rpcSerializer.decodeKey(proto.getName());
SnapshotVersion version = rpcSerializer.decodeVersion(proto.getReadTime());
MutableDocument result = MutableDocument.newNoDocument(key, version);
return hasCommittedMutations ? result.setHasCommittedMutations() : result;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class MemoryDocumentOverlayCache method getOverlays.
@Override
public Map<DocumentKey, Overlay> getOverlays(String collectionGroup, int sinceBatchId, int count) {
// NOTE: This method is only used by the backfiller, which will not run for memory persistence;
// therefore, this method is being implemented only so that the test suite for
// `LevelDbDocumentOverlayCache` can be re-used by the test suite for this class.
SortedMap<Integer, Map<DocumentKey, Overlay>> batchIdToOverlays = new TreeMap<>();
for (Overlay overlay : overlays.values()) {
DocumentKey key = overlay.getKey();
if (!key.getCollectionGroup().equals(collectionGroup)) {
continue;
}
if (overlay.getLargestBatchId() > sinceBatchId) {
Map<DocumentKey, Overlay> overlays = batchIdToOverlays.get(overlay.getLargestBatchId());
if (overlays == null) {
overlays = new HashMap<>();
batchIdToOverlays.put(overlay.getLargestBatchId(), overlays);
}
overlays.put(overlay.getKey(), overlay);
}
}
Map<DocumentKey, Overlay> result = new HashMap<>();
for (Map<DocumentKey, Overlay> overlays : batchIdToOverlays.values()) {
result.putAll(overlays);
if (result.size() >= count) {
break;
}
}
return result;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class ReferenceSet method referencesForId.
/**
* Returns all of the document keys that have had references added for the given ID.
*/
public ImmutableSortedSet<DocumentKey> referencesForId(int target) {
DocumentKey emptyKey = DocumentKey.empty();
DocumentReference startRef = new DocumentReference(emptyKey, target);
Iterator<DocumentReference> iterator = referencesByTarget.iteratorFrom(startRef);
ImmutableSortedSet<DocumentKey> keys = DocumentKey.emptyKeySet();
while (iterator.hasNext()) {
DocumentReference reference = iterator.next();
if (reference.getId() == target) {
keys = keys.insert(reference.getKey());
} else {
break;
}
}
return keys;
}
Aggregations