84 lines
4.2 KiB
Java
84 lines
4.2 KiB
Java
package com.google.firebase.firestore.local;
|
|
|
|
import com.google.firebase.database.collection.ImmutableSortedMap;
|
|
import com.google.firebase.firestore.model.Document;
|
|
import com.google.firebase.firestore.model.DocumentCollections;
|
|
import com.google.firebase.firestore.model.DocumentKey;
|
|
import com.google.firebase.firestore.model.FieldIndex;
|
|
import com.google.firebase.firestore.model.MutableDocument;
|
|
import com.google.firebase.firestore.model.ResourcePath;
|
|
import com.google.firebase.firestore.model.SnapshotVersion;
|
|
import com.google.firebase.firestore.util.Assert;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes2.dex */
|
|
final class MemoryRemoteDocumentCache implements RemoteDocumentCache {
|
|
private ImmutableSortedMap<DocumentKey, Document> docs = DocumentCollections.emptyDocumentMap();
|
|
private IndexManager indexManager;
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final void add(MutableDocument mutableDocument, SnapshotVersion snapshotVersion) {
|
|
Assert.hardAssert(this.indexManager != null, "setIndexManager() not called", new Object[0]);
|
|
Assert.hardAssert(!snapshotVersion.equals(SnapshotVersion.NONE), "Cannot add document to the RemoteDocumentCache with a read time of zero", new Object[0]);
|
|
this.docs = this.docs.insert(mutableDocument.getKey(), mutableDocument.mutableCopy().setReadTime(snapshotVersion));
|
|
this.indexManager.addToCollectionParentIndex(mutableDocument.getKey().getCollectionPath());
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final void removeAll(Collection<DocumentKey> collection) {
|
|
Assert.hardAssert(this.indexManager != null, "setIndexManager() not called", new Object[0]);
|
|
ImmutableSortedMap<DocumentKey, Document> emptyDocumentMap = DocumentCollections.emptyDocumentMap();
|
|
for (DocumentKey documentKey : collection) {
|
|
this.docs = this.docs.remove(documentKey);
|
|
emptyDocumentMap = emptyDocumentMap.insert(documentKey, MutableDocument.newNoDocument(documentKey, SnapshotVersion.NONE));
|
|
}
|
|
this.indexManager.updateIndexEntries(emptyDocumentMap);
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final MutableDocument get(DocumentKey documentKey) {
|
|
Document document = this.docs.get(documentKey);
|
|
return document != null ? document.mutableCopy() : MutableDocument.newInvalidDocument(documentKey);
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> iterable) {
|
|
HashMap hashMap = new HashMap();
|
|
for (DocumentKey documentKey : iterable) {
|
|
hashMap.put(documentKey, get(documentKey));
|
|
}
|
|
return hashMap;
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final Map<DocumentKey, MutableDocument> getAll(String str, FieldIndex.IndexOffset indexOffset, int i) {
|
|
throw new UnsupportedOperationException("getAll(String, IndexOffset, int) is not supported.");
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final Map<DocumentKey, MutableDocument> getAll(ResourcePath resourcePath, FieldIndex.IndexOffset indexOffset) {
|
|
HashMap hashMap = new HashMap();
|
|
Iterator<Map.Entry<DocumentKey, Document>> iteratorFrom = this.docs.iteratorFrom(DocumentKey.fromPath(resourcePath.append("")));
|
|
while (iteratorFrom.hasNext()) {
|
|
Map.Entry<DocumentKey, Document> next = iteratorFrom.next();
|
|
Document value = next.getValue();
|
|
DocumentKey key = next.getKey();
|
|
if (!resourcePath.isPrefixOf(key.getPath())) {
|
|
break;
|
|
}
|
|
if (key.getPath().length() <= resourcePath.length() + 1 && FieldIndex.IndexOffset.fromDocument(value).compareTo(indexOffset) > 0) {
|
|
hashMap.put(value.getKey(), value.mutableCopy());
|
|
}
|
|
}
|
|
return hashMap;
|
|
}
|
|
|
|
@Override // com.google.firebase.firestore.local.RemoteDocumentCache
|
|
public final void setIndexManager(IndexManager indexManager) {
|
|
this.indexManager = indexManager;
|
|
}
|
|
}
|