602 lines
29 KiB
Java
602 lines
29 KiB
Java
package com.google.firebase.firestore.local;
|
|
|
|
import android.util.SparseArray;
|
|
import com.google.firebase.Timestamp;
|
|
import com.google.firebase.database.collection.ImmutableSortedMap;
|
|
import com.google.firebase.database.collection.ImmutableSortedSet;
|
|
import com.google.firebase.firestore.auth.User;
|
|
import com.google.firebase.firestore.core.Query;
|
|
import com.google.firebase.firestore.core.Target;
|
|
import com.google.firebase.firestore.core.TargetIdGenerator;
|
|
import com.google.firebase.firestore.local.LocalStore;
|
|
import com.google.firebase.firestore.local.LruGarbageCollector;
|
|
import com.google.firebase.firestore.model.Document;
|
|
import com.google.firebase.firestore.model.DocumentKey;
|
|
import com.google.firebase.firestore.model.MutableDocument;
|
|
import com.google.firebase.firestore.model.ObjectValue;
|
|
import com.google.firebase.firestore.model.SnapshotVersion;
|
|
import com.google.firebase.firestore.model.mutation.Mutation;
|
|
import com.google.firebase.firestore.model.mutation.MutationBatch;
|
|
import com.google.firebase.firestore.model.mutation.MutationBatchResult;
|
|
import com.google.firebase.firestore.model.mutation.PatchMutation;
|
|
import com.google.firebase.firestore.model.mutation.Precondition;
|
|
import com.google.firebase.firestore.remote.RemoteEvent;
|
|
import com.google.firebase.firestore.remote.TargetChange;
|
|
import com.google.firebase.firestore.util.Assert;
|
|
import com.google.firebase.firestore.util.Logger;
|
|
import com.google.firebase.firestore.util.Supplier;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.concurrent.TimeUnit;
|
|
import o.QwV;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class LocalStore {
|
|
private static final long RESUME_TOKEN_MAX_AGE_SECONDS = TimeUnit.MINUTES.toSeconds(5);
|
|
private final BundleCache bundleCache;
|
|
private DocumentOverlayCache documentOverlayCache;
|
|
private IndexManager indexManager;
|
|
private LocalDocumentsView localDocuments;
|
|
private final ReferenceSet localViewReferences;
|
|
private MutationQueue mutationQueue;
|
|
private final Persistence persistence;
|
|
private final SparseArray<TargetData> queryDataByTarget;
|
|
private final QueryEngine queryEngine;
|
|
private final RemoteDocumentCache remoteDocuments;
|
|
private final TargetCache targetCache;
|
|
private final Map<Target, Integer> targetIdByTarget;
|
|
private final TargetIdGenerator targetIdGenerator;
|
|
|
|
public LocalStore(Persistence persistence, QueryEngine queryEngine, User user) {
|
|
Assert.hardAssert(persistence.isStarted(), "LocalStore was passed an unstarted persistence implementation", new Object[0]);
|
|
this.persistence = persistence;
|
|
this.queryEngine = queryEngine;
|
|
TargetCache targetCache = persistence.getTargetCache();
|
|
this.targetCache = targetCache;
|
|
this.bundleCache = persistence.getBundleCache();
|
|
this.targetIdGenerator = TargetIdGenerator.forTargetCache(targetCache.getHighestTargetId());
|
|
this.remoteDocuments = persistence.getRemoteDocumentCache();
|
|
ReferenceSet referenceSet = new ReferenceSet();
|
|
this.localViewReferences = referenceSet;
|
|
this.queryDataByTarget = new SparseArray<>();
|
|
this.targetIdByTarget = new HashMap();
|
|
persistence.getReferenceDelegate().setInMemoryPins(referenceSet);
|
|
initializeUserComponents(user);
|
|
}
|
|
|
|
private void initializeUserComponents(User user) {
|
|
IndexManager indexManager = this.persistence.getIndexManager(user);
|
|
this.indexManager = indexManager;
|
|
this.mutationQueue = this.persistence.getMutationQueue(user, indexManager);
|
|
DocumentOverlayCache documentOverlayCache = this.persistence.getDocumentOverlayCache(user);
|
|
this.documentOverlayCache = documentOverlayCache;
|
|
this.localDocuments = new LocalDocumentsView(this.remoteDocuments, this.mutationQueue, documentOverlayCache, this.indexManager);
|
|
this.remoteDocuments.setIndexManager(this.indexManager);
|
|
this.queryEngine.initialize(this.localDocuments, this.indexManager);
|
|
}
|
|
|
|
public final void start() {
|
|
this.persistence.getOverlayMigrationManager().run();
|
|
startIndexManager();
|
|
startMutationQueue();
|
|
}
|
|
|
|
private void startIndexManager() {
|
|
this.persistence.runTransaction("Start IndexManager", new Runnable(this) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda15
|
|
public final LocalStore f$0;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m194xf9470190();
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$startIndexManager$0$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m194xf9470190() {
|
|
this.indexManager.start();
|
|
}
|
|
|
|
private void startMutationQueue() {
|
|
this.persistence.runTransaction("Start MutationQueue", new Runnable(this) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda19
|
|
public final LocalStore f$0;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m195xa2ea7b8c();
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$startMutationQueue$1$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m195xa2ea7b8c() {
|
|
this.mutationQueue.start();
|
|
}
|
|
|
|
public final ImmutableSortedMap<DocumentKey, Document> handleUserChange(User user) {
|
|
List<MutationBatch> allMutationBatches = this.mutationQueue.getAllMutationBatches();
|
|
initializeUserComponents(user);
|
|
startIndexManager();
|
|
startMutationQueue();
|
|
List<MutationBatch> allMutationBatches2 = this.mutationQueue.getAllMutationBatches();
|
|
ImmutableSortedSet<DocumentKey> emptyKeySet = DocumentKey.emptyKeySet();
|
|
Iterator it = Arrays.asList(allMutationBatches, allMutationBatches2).iterator();
|
|
while (it.hasNext()) {
|
|
Iterator it2 = ((List) it.next()).iterator();
|
|
while (it2.hasNext()) {
|
|
Iterator<Mutation> it3 = ((MutationBatch) it2.next()).getMutations().iterator();
|
|
while (it3.hasNext()) {
|
|
emptyKeySet = emptyKeySet.insert(it3.next().getKey());
|
|
}
|
|
}
|
|
}
|
|
return this.localDocuments.getDocuments(emptyKeySet);
|
|
}
|
|
|
|
public final LocalDocumentsResult writeLocally(final List<Mutation> list) {
|
|
final Timestamp now = Timestamp.now();
|
|
final HashSet hashSet = new HashSet();
|
|
Iterator<Mutation> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
hashSet.add(it.next().getKey());
|
|
}
|
|
return (LocalDocumentsResult) this.persistence.runTransaction("Locally write mutations", new Supplier(this, hashSet, list, now) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda2
|
|
public final LocalStore f$0;
|
|
public final Set f$1;
|
|
public final List f$2;
|
|
public final Timestamp f$3;
|
|
|
|
@Override // com.google.firebase.firestore.util.Supplier
|
|
public final Object get() {
|
|
return this.f$0.m196x4f0ff958(this.f$1, this.f$2, this.f$3);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = hashSet;
|
|
this.f$2 = list;
|
|
this.f$3 = now;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$writeLocally$2$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ LocalDocumentsResult m196x4f0ff958(Set set, List list, Timestamp timestamp) {
|
|
Map<DocumentKey, MutableDocument> all = this.remoteDocuments.getAll(set);
|
|
HashSet hashSet = new HashSet();
|
|
for (Map.Entry<DocumentKey, MutableDocument> entry : all.entrySet()) {
|
|
if (!entry.getValue().isValidDocument()) {
|
|
hashSet.add(entry.getKey());
|
|
}
|
|
}
|
|
Map<DocumentKey, OverlayedDocument> overlayedDocuments = this.localDocuments.getOverlayedDocuments(all);
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator it = list.iterator();
|
|
while (it.hasNext()) {
|
|
Mutation mutation = (Mutation) it.next();
|
|
ObjectValue extractTransformBaseValue = mutation.extractTransformBaseValue(overlayedDocuments.get(mutation.getKey()).getDocument());
|
|
if (extractTransformBaseValue != null) {
|
|
arrayList.add(new PatchMutation(mutation.getKey(), extractTransformBaseValue, extractTransformBaseValue.getFieldMask(), Precondition.exists(true)));
|
|
}
|
|
}
|
|
MutationBatch addMutationBatch = this.mutationQueue.addMutationBatch(timestamp, arrayList, list);
|
|
this.documentOverlayCache.saveOverlays(addMutationBatch.getBatchId(), addMutationBatch.applyToLocalDocumentSet(overlayedDocuments, hashSet));
|
|
return LocalDocumentsResult.fromOverlayedDocuments(addMutationBatch.getBatchId(), overlayedDocuments);
|
|
}
|
|
|
|
public final ImmutableSortedMap<DocumentKey, Document> acknowledgeBatch(final MutationBatchResult mutationBatchResult) {
|
|
return (ImmutableSortedMap) this.persistence.runTransaction("Acknowledge batch", new Supplier(this, mutationBatchResult) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda1
|
|
public final LocalStore f$0;
|
|
public final MutationBatchResult f$1;
|
|
|
|
@Override // com.google.firebase.firestore.util.Supplier
|
|
public final Object get() {
|
|
return this.f$0.m186xd0c8f3b2(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = mutationBatchResult;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$acknowledgeBatch$3$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ ImmutableSortedMap m186xd0c8f3b2(MutationBatchResult mutationBatchResult) {
|
|
MutationBatch batch = mutationBatchResult.getBatch();
|
|
this.mutationQueue.acknowledgeBatch(batch, mutationBatchResult.getStreamToken());
|
|
applyWriteToRemoteDocuments(mutationBatchResult);
|
|
this.mutationQueue.performConsistencyCheck();
|
|
this.documentOverlayCache.removeOverlaysForBatchId(mutationBatchResult.getBatch().getBatchId());
|
|
this.localDocuments.recalculateAndSaveOverlays(getKeysWithTransformResults(mutationBatchResult));
|
|
return this.localDocuments.getDocuments(batch.getKeys());
|
|
}
|
|
|
|
private Set<DocumentKey> getKeysWithTransformResults(MutationBatchResult mutationBatchResult) {
|
|
HashSet hashSet = new HashSet();
|
|
for (int i = 0; i < mutationBatchResult.getMutationResults().size(); i++) {
|
|
if (!mutationBatchResult.getMutationResults().get(i).getTransformResults().isEmpty()) {
|
|
hashSet.add(mutationBatchResult.getBatch().getMutations().get(i).getKey());
|
|
}
|
|
}
|
|
return hashSet;
|
|
}
|
|
|
|
public final ImmutableSortedMap<DocumentKey, Document> rejectBatch(final int i) {
|
|
return (ImmutableSortedMap) this.persistence.runTransaction("Reject batch", new Supplier(this, i) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda11
|
|
public final LocalStore f$0;
|
|
public final int f$1;
|
|
|
|
@Override // com.google.firebase.firestore.util.Supplier
|
|
public final Object get() {
|
|
return this.f$0.m191x1ab75fae(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = i;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$rejectBatch$4$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ ImmutableSortedMap m191x1ab75fae(int i) {
|
|
MutationBatch lookupMutationBatch = this.mutationQueue.lookupMutationBatch(i);
|
|
Assert.hardAssert(lookupMutationBatch != null, "Attempt to reject nonexistent batch!", new Object[0]);
|
|
this.mutationQueue.removeMutationBatch(lookupMutationBatch);
|
|
this.mutationQueue.performConsistencyCheck();
|
|
this.documentOverlayCache.removeOverlaysForBatchId(i);
|
|
this.localDocuments.recalculateAndSaveOverlays(lookupMutationBatch.getKeys());
|
|
return this.localDocuments.getDocuments(lookupMutationBatch.getKeys());
|
|
}
|
|
|
|
public final QwV getLastStreamToken() {
|
|
return this.mutationQueue.getLastStreamToken();
|
|
}
|
|
|
|
public final void setLastStreamToken(final QwV qwV) {
|
|
this.persistence.runTransaction("Set stream token", new Runnable(this, qwV) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda4
|
|
public final LocalStore f$0;
|
|
public final QwV f$1;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m193x6c1835ed(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = qwV;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$setLastStreamToken$5$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m193x6c1835ed(QwV qwV) {
|
|
this.mutationQueue.setLastStreamToken(qwV);
|
|
}
|
|
|
|
public final SnapshotVersion getLastRemoteSnapshotVersion() {
|
|
return this.targetCache.getLastRemoteSnapshotVersion();
|
|
}
|
|
|
|
public final ImmutableSortedMap<DocumentKey, Document> applyRemoteEvent(final RemoteEvent remoteEvent) {
|
|
final SnapshotVersion snapshotVersion = remoteEvent.getSnapshotVersion();
|
|
return (ImmutableSortedMap) this.persistence.runTransaction("Apply remote event", new Supplier(this, remoteEvent, snapshotVersion) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda10
|
|
public final LocalStore f$0;
|
|
public final RemoteEvent f$1;
|
|
public final SnapshotVersion f$2;
|
|
|
|
@Override // com.google.firebase.firestore.util.Supplier
|
|
public final Object get() {
|
|
return this.f$0.m188xfb616aa7(this.f$1, this.f$2);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = remoteEvent;
|
|
this.f$2 = snapshotVersion;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$applyRemoteEvent$6$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ ImmutableSortedMap m188xfb616aa7(RemoteEvent remoteEvent, SnapshotVersion snapshotVersion) {
|
|
Map<Integer, TargetChange> targetChanges = remoteEvent.getTargetChanges();
|
|
long currentSequenceNumber = this.persistence.getReferenceDelegate().getCurrentSequenceNumber();
|
|
for (Map.Entry<Integer, TargetChange> entry : targetChanges.entrySet()) {
|
|
int intValue = entry.getKey().intValue();
|
|
TargetChange value = entry.getValue();
|
|
TargetData targetData = this.queryDataByTarget.get(intValue);
|
|
if (targetData != null) {
|
|
this.targetCache.removeMatchingKeys(value.getRemovedDocuments(), intValue);
|
|
this.targetCache.addMatchingKeys(value.getAddedDocuments(), intValue);
|
|
TargetData withSequenceNumber = targetData.withSequenceNumber(currentSequenceNumber);
|
|
if (remoteEvent.getTargetMismatches().contains(Integer.valueOf(intValue))) {
|
|
withSequenceNumber = withSequenceNumber.withResumeToken(QwV.a, SnapshotVersion.NONE).withLastLimboFreeSnapshotVersion(SnapshotVersion.NONE);
|
|
} else if (value.getResumeToken().g() != 0) {
|
|
withSequenceNumber = withSequenceNumber.withResumeToken(value.getResumeToken(), remoteEvent.getSnapshotVersion());
|
|
}
|
|
this.queryDataByTarget.put(intValue, withSequenceNumber);
|
|
if (shouldPersistTargetData(targetData, withSequenceNumber, value)) {
|
|
this.targetCache.updateTargetData(withSequenceNumber);
|
|
}
|
|
}
|
|
}
|
|
Map<DocumentKey, MutableDocument> documentUpdates = remoteEvent.getDocumentUpdates();
|
|
Set<DocumentKey> resolvedLimboDocuments = remoteEvent.getResolvedLimboDocuments();
|
|
for (DocumentKey documentKey : documentUpdates.keySet()) {
|
|
if (resolvedLimboDocuments.contains(documentKey)) {
|
|
this.persistence.getReferenceDelegate().updateLimboDocument(documentKey);
|
|
}
|
|
}
|
|
DocumentChangeResult populateDocumentChanges = populateDocumentChanges(documentUpdates);
|
|
Map<DocumentKey, MutableDocument> map = populateDocumentChanges.changedDocuments;
|
|
SnapshotVersion lastRemoteSnapshotVersion = this.targetCache.getLastRemoteSnapshotVersion();
|
|
if (!snapshotVersion.equals(SnapshotVersion.NONE)) {
|
|
Assert.hardAssert(snapshotVersion.compareTo(lastRemoteSnapshotVersion) >= 0, "Watch stream reverted to previous snapshot?? (%s < %s)", snapshotVersion, lastRemoteSnapshotVersion);
|
|
this.targetCache.setLastRemoteSnapshotVersion(snapshotVersion);
|
|
}
|
|
return this.localDocuments.getLocalViewOfDocuments(map, populateDocumentChanges.existenceChangedKeys);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public static class DocumentChangeResult {
|
|
private final Map<DocumentKey, MutableDocument> changedDocuments;
|
|
private final Set<DocumentKey> existenceChangedKeys;
|
|
|
|
private DocumentChangeResult(Map<DocumentKey, MutableDocument> map, Set<DocumentKey> set) {
|
|
this.changedDocuments = map;
|
|
this.existenceChangedKeys = set;
|
|
}
|
|
}
|
|
|
|
private DocumentChangeResult populateDocumentChanges(Map<DocumentKey, MutableDocument> map) {
|
|
HashMap hashMap = new HashMap();
|
|
ArrayList arrayList = new ArrayList();
|
|
HashSet hashSet = new HashSet();
|
|
Map<DocumentKey, MutableDocument> all = this.remoteDocuments.getAll(map.keySet());
|
|
for (Map.Entry<DocumentKey, MutableDocument> entry : map.entrySet()) {
|
|
DocumentKey key = entry.getKey();
|
|
MutableDocument value = entry.getValue();
|
|
MutableDocument mutableDocument = all.get(key);
|
|
if (value.isFoundDocument() != mutableDocument.isFoundDocument()) {
|
|
hashSet.add(key);
|
|
}
|
|
if (value.isNoDocument() && value.getVersion().equals(SnapshotVersion.NONE)) {
|
|
arrayList.add(value.getKey());
|
|
hashMap.put(key, value);
|
|
} else if (!mutableDocument.isValidDocument() || value.getVersion().compareTo(mutableDocument.getVersion()) > 0 || (value.getVersion().compareTo(mutableDocument.getVersion()) == 0 && mutableDocument.hasPendingWrites())) {
|
|
Assert.hardAssert(!SnapshotVersion.NONE.equals(value.getReadTime()), "Cannot add a document when the remote version is zero", new Object[0]);
|
|
this.remoteDocuments.add(value, value.getReadTime());
|
|
hashMap.put(key, value);
|
|
} else {
|
|
Logger.debug("LocalStore", "Ignoring outdated watch update for %s.Current version: %s Watch version: %s", key, mutableDocument.getVersion(), value.getVersion());
|
|
}
|
|
}
|
|
this.remoteDocuments.removeAll(arrayList);
|
|
return new DocumentChangeResult(hashMap, hashSet);
|
|
}
|
|
|
|
private static boolean shouldPersistTargetData(TargetData targetData, TargetData targetData2, TargetChange targetChange) {
|
|
return (targetData.getResumeToken().g() == 0) || targetData2.getSnapshotVersion().getTimestamp().getSeconds() - targetData.getSnapshotVersion().getTimestamp().getSeconds() >= RESUME_TOKEN_MAX_AGE_SECONDS || (targetChange.getAddedDocuments().size() + targetChange.getModifiedDocuments().size()) + targetChange.getRemovedDocuments().size() > 0;
|
|
}
|
|
|
|
public final void notifyLocalViewChanges(final List<LocalViewChanges> list) {
|
|
this.persistence.runTransaction("notifyLocalViewChanges", new Runnable(this, list) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda13
|
|
public final LocalStore f$0;
|
|
public final List f$1;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m190x6c8bed50(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = list;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$notifyLocalViewChanges$7$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m190x6c8bed50(List list) {
|
|
Iterator it = list.iterator();
|
|
while (it.hasNext()) {
|
|
LocalViewChanges localViewChanges = (LocalViewChanges) it.next();
|
|
int targetId = localViewChanges.getTargetId();
|
|
this.localViewReferences.addReferences(localViewChanges.getAdded(), targetId);
|
|
ImmutableSortedSet<DocumentKey> removed = localViewChanges.getRemoved();
|
|
Iterator<DocumentKey> it2 = removed.iterator();
|
|
while (it2.hasNext()) {
|
|
this.persistence.getReferenceDelegate().removeReference(it2.next());
|
|
}
|
|
this.localViewReferences.removeReferences(removed, targetId);
|
|
if (!localViewChanges.isFromCache()) {
|
|
TargetData targetData = this.queryDataByTarget.get(targetId);
|
|
Assert.hardAssert(targetData != null, "Can't set limbo-free snapshot version for unknown target: %s", Integer.valueOf(targetId));
|
|
this.queryDataByTarget.put(targetId, targetData.withLastLimboFreeSnapshotVersion(targetData.getSnapshotVersion()));
|
|
}
|
|
}
|
|
}
|
|
|
|
public final MutationBatch getNextMutationBatch(int i) {
|
|
return this.mutationQueue.getNextMutationBatchAfterBatchId(i);
|
|
}
|
|
|
|
public final TargetData allocateTarget(final Target target) {
|
|
int i;
|
|
TargetData targetData = this.targetCache.getTargetData(target);
|
|
if (targetData != null) {
|
|
i = targetData.getTargetId();
|
|
} else {
|
|
final AllocateQueryHolder allocateQueryHolder = new AllocateQueryHolder();
|
|
this.persistence.runTransaction("Allocate target", new Runnable(this, allocateQueryHolder, target) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda5
|
|
public final LocalStore f$0;
|
|
public final LocalStore.AllocateQueryHolder f$1;
|
|
public final Target f$2;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m187x5de91a9d(this.f$1, this.f$2);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = allocateQueryHolder;
|
|
this.f$2 = target;
|
|
}
|
|
});
|
|
i = allocateQueryHolder.targetId;
|
|
targetData = allocateQueryHolder.cached;
|
|
}
|
|
if (this.queryDataByTarget.get(i) == null) {
|
|
this.queryDataByTarget.put(i, targetData);
|
|
this.targetIdByTarget.put(target, Integer.valueOf(i));
|
|
}
|
|
return targetData;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$allocateTarget$8$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m187x5de91a9d(AllocateQueryHolder allocateQueryHolder, Target target) {
|
|
allocateQueryHolder.targetId = this.targetIdGenerator.nextId();
|
|
allocateQueryHolder.cached = new TargetData(target, allocateQueryHolder.targetId, this.persistence.getReferenceDelegate().getCurrentSequenceNumber(), QueryPurpose.LISTEN);
|
|
this.targetCache.addTargetData(allocateQueryHolder.cached);
|
|
}
|
|
|
|
final TargetData getTargetData(Target target) {
|
|
Integer num = this.targetIdByTarget.get(target);
|
|
if (num != null) {
|
|
return this.queryDataByTarget.get(num.intValue());
|
|
}
|
|
return this.targetCache.getTargetData(target);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public static class AllocateQueryHolder {
|
|
TargetData cached;
|
|
int targetId;
|
|
|
|
private AllocateQueryHolder() {
|
|
}
|
|
}
|
|
|
|
public final void releaseTarget(final int i) {
|
|
this.persistence.runTransaction("Release target", new Runnable(this, i) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda18
|
|
public final LocalStore f$0;
|
|
public final int f$1;
|
|
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
this.f$0.m192x1dfd2d2e(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = i;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$releaseTarget$16$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ void m192x1dfd2d2e(int i) {
|
|
TargetData targetData = this.queryDataByTarget.get(i);
|
|
Assert.hardAssert(targetData != null, "Tried to release nonexistent target: %s", Integer.valueOf(i));
|
|
Iterator<DocumentKey> it = this.localViewReferences.removeReferencesForId(i).iterator();
|
|
while (it.hasNext()) {
|
|
this.persistence.getReferenceDelegate().removeReference(it.next());
|
|
}
|
|
this.persistence.getReferenceDelegate().removeTarget(targetData);
|
|
this.queryDataByTarget.remove(i);
|
|
this.targetIdByTarget.remove(targetData.getTarget());
|
|
}
|
|
|
|
public final QueryResult executeQuery(Query query, boolean z) {
|
|
TargetData targetData = getTargetData(query.toTarget());
|
|
SnapshotVersion snapshotVersion = SnapshotVersion.NONE;
|
|
ImmutableSortedSet<DocumentKey> emptyKeySet = DocumentKey.emptyKeySet();
|
|
if (targetData != null) {
|
|
snapshotVersion = targetData.getLastLimboFreeSnapshotVersion();
|
|
emptyKeySet = this.targetCache.getMatchingKeysForTargetId(targetData.getTargetId());
|
|
}
|
|
QueryEngine queryEngine = this.queryEngine;
|
|
if (!z) {
|
|
snapshotVersion = SnapshotVersion.NONE;
|
|
}
|
|
return new QueryResult(queryEngine.getDocumentsMatchingQuery(query, snapshotVersion, emptyKeySet), emptyKeySet);
|
|
}
|
|
|
|
private void applyWriteToRemoteDocuments(MutationBatchResult mutationBatchResult) {
|
|
MutationBatch batch = mutationBatchResult.getBatch();
|
|
for (DocumentKey documentKey : batch.getKeys()) {
|
|
MutableDocument mutableDocument = this.remoteDocuments.get(documentKey);
|
|
SnapshotVersion snapshotVersion = mutationBatchResult.getDocVersions().get(documentKey);
|
|
Assert.hardAssert(snapshotVersion != null, "docVersions should contain every doc in the write.", new Object[0]);
|
|
if (mutableDocument.getVersion().compareTo(snapshotVersion) < 0) {
|
|
batch.applyToRemoteDocument(mutableDocument, mutationBatchResult);
|
|
if (mutableDocument.isValidDocument()) {
|
|
this.remoteDocuments.add(mutableDocument, mutationBatchResult.getCommitVersion());
|
|
}
|
|
}
|
|
}
|
|
this.mutationQueue.removeMutationBatch(batch);
|
|
}
|
|
|
|
public final LruGarbageCollector.Results collectGarbage(final LruGarbageCollector lruGarbageCollector) {
|
|
return (LruGarbageCollector.Results) this.persistence.runTransaction("Collect garbage", new Supplier(this, lruGarbageCollector) { // from class: com.google.firebase.firestore.local.LocalStore$$ExternalSyntheticLambda16
|
|
public final LocalStore f$0;
|
|
public final LruGarbageCollector f$1;
|
|
|
|
@Override // com.google.firebase.firestore.util.Supplier
|
|
public final Object get() {
|
|
return this.f$0.m189x1db5499a(this.f$1);
|
|
}
|
|
|
|
{
|
|
this.f$0 = this;
|
|
this.f$1 = lruGarbageCollector;
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: lambda$collectGarbage$17$com-google-firebase-firestore-local-LocalStore, reason: not valid java name */
|
|
public final /* synthetic */ LruGarbageCollector.Results m189x1db5499a(LruGarbageCollector lruGarbageCollector) {
|
|
return lruGarbageCollector.collect(this.queryDataByTarget);
|
|
}
|
|
|
|
public final LocalDocumentsView getLocalDocumentsForCurrentUser() {
|
|
return this.localDocuments;
|
|
}
|
|
|
|
public final IndexManager getIndexManagerForCurrentUser() {
|
|
return this.indexManager;
|
|
}
|
|
}
|