Search in sources :

Example 11 with DocumentKey

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;
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey) ArrayList(java.util.ArrayList)

Example 12 with DocumentKey

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);
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Example 13 with DocumentKey

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;
}
Also used : SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) DocumentKey(com.google.firebase.firestore.model.DocumentKey) MutableDocument(com.google.firebase.firestore.model.MutableDocument)

Example 14 with DocumentKey

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;
}
Also used : HashMap(java.util.HashMap) DocumentKey(com.google.firebase.firestore.model.DocumentKey) TreeMap(java.util.TreeMap) Overlay(com.google.firebase.firestore.model.mutation.Overlay) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) SortedMap(java.util.SortedMap)

Example 15 with DocumentKey

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;
}
Also used : DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Aggregations

DocumentKey (com.google.firebase.firestore.model.DocumentKey)134 MutableDocument (com.google.firebase.firestore.model.MutableDocument)52 Test (org.junit.Test)36 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)25 Document (com.google.firebase.firestore.model.Document)23 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)16 Mutation (com.google.firebase.firestore.model.mutation.Mutation)15 Map (java.util.Map)15 ResourcePath (com.google.firebase.firestore.model.ResourcePath)13 MutationBatch (com.google.firebase.firestore.model.mutation.MutationBatch)11 HashSet (java.util.HashSet)11 Overlay (com.google.firebase.firestore.model.mutation.Overlay)10 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)9 TestUtil.patchMutation (com.google.firebase.firestore.testutil.TestUtil.patchMutation)7 TestUtil.setMutation (com.google.firebase.firestore.testutil.TestUtil.setMutation)7 ByteString (com.google.protobuf.ByteString)7 Query (com.google.firebase.firestore.core.Query)6 ObjectValue (com.google.firebase.firestore.model.ObjectValue)6 Timestamp (com.google.firebase.Timestamp)5