what-the-bank/sources/com/google/firebase/firestore/local/IndexBackfiller.java

157 lines
7.5 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.firestore.local;
import com.google.common.base.Supplier;
import com.google.firebase.firestore.local.IndexBackfiller;
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.FieldIndex;
import com.google.firebase.firestore.util.AsyncQueue;
import com.google.firebase.firestore.util.Logger;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class IndexBackfiller {
private static final long INITIAL_BACKFILL_DELAY_MS = TimeUnit.SECONDS.toMillis(15);
private static final long REGULAR_BACKFILL_DELAY_MS = TimeUnit.MINUTES.toMillis(1);
private final Supplier<IndexManager> indexManagerOfCurrentUser;
private final Supplier<LocalDocumentsView> localDocumentsViewOfCurrentUser;
private int maxDocumentsToProcess;
private final Persistence persistence;
private final Scheduler scheduler;
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public IndexBackfiller(com.google.firebase.firestore.local.Persistence r3, com.google.firebase.firestore.util.AsyncQueue r4, final com.google.firebase.firestore.local.LocalStore r5) {
/*
r2 = this;
java.util.Objects.requireNonNull(r5)
com.google.firebase.firestore.local.IndexBackfiller$$ExternalSyntheticLambda1 r0 = new com.google.firebase.firestore.local.IndexBackfiller$$ExternalSyntheticLambda1
r0.<init>(r5)
java.util.Objects.requireNonNull(r5)
com.google.firebase.firestore.local.IndexBackfiller$$ExternalSyntheticLambda2 r1 = new com.google.firebase.firestore.local.IndexBackfiller$$ExternalSyntheticLambda2
r1.<init>(r5)
r2.<init>(r3, r4, r0, r1)
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.firebase.firestore.local.IndexBackfiller.<init>(com.google.firebase.firestore.local.Persistence, com.google.firebase.firestore.util.AsyncQueue, com.google.firebase.firestore.local.LocalStore):void");
}
public IndexBackfiller(Persistence persistence, AsyncQueue asyncQueue, Supplier<IndexManager> supplier, Supplier<LocalDocumentsView> supplier2) {
this.maxDocumentsToProcess = 50;
this.persistence = persistence;
this.scheduler = new Scheduler(this, asyncQueue);
this.indexManagerOfCurrentUser = supplier;
this.localDocumentsViewOfCurrentUser = supplier2;
}
/* loaded from: classes2.dex */
public class Scheduler implements com.google.firebase.firestore.local.Scheduler {
private final AsyncQueue asyncQueue;
private AsyncQueue.DelayedTask backfillTask;
final IndexBackfiller this$0;
public Scheduler(IndexBackfiller indexBackfiller, AsyncQueue asyncQueue) {
this.this$0 = indexBackfiller;
this.asyncQueue = asyncQueue;
}
@Override // com.google.firebase.firestore.local.Scheduler
public void start() {
scheduleBackfill(IndexBackfiller.INITIAL_BACKFILL_DELAY_MS);
}
private void scheduleBackfill(long j) {
this.backfillTask = this.asyncQueue.enqueueAfterDelay(AsyncQueue.TimerId.INDEX_BACKFILL, j, new Runnable(this) { // from class: com.google.firebase.firestore.local.IndexBackfiller$Scheduler$$ExternalSyntheticLambda0
public final IndexBackfiller.Scheduler f$0;
@Override // java.lang.Runnable
public final void run() {
this.f$0.m185x4c716e24();
}
{
this.f$0 = this;
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$scheduleBackfill$0$com-google-firebase-firestore-local-IndexBackfiller$Scheduler, reason: not valid java name */
public /* synthetic */ void m185x4c716e24() {
Logger.debug("IndexBackfiller", "Documents written: %s", Integer.valueOf(this.this$0.backfill()));
scheduleBackfill(IndexBackfiller.REGULAR_BACKFILL_DELAY_MS);
}
}
public int backfill() {
return ((Integer) this.persistence.runTransaction("Backfill Indexes", new com.google.firebase.firestore.util.Supplier(this) { // from class: com.google.firebase.firestore.local.IndexBackfiller$$ExternalSyntheticLambda0
public final IndexBackfiller f$0;
@Override // com.google.firebase.firestore.util.Supplier
public final Object get() {
return this.f$0.m184x14d875f6();
}
{
this.f$0 = this;
}
})).intValue();
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$backfill$0$com-google-firebase-firestore-local-IndexBackfiller, reason: not valid java name */
public /* synthetic */ Integer m184x14d875f6() {
return Integer.valueOf(writeIndexEntries());
}
private int writeIndexEntries() {
IndexManager indexManager = this.indexManagerOfCurrentUser.get();
HashSet hashSet = new HashSet();
int i = this.maxDocumentsToProcess;
while (i > 0) {
String nextCollectionGroupToUpdate = indexManager.getNextCollectionGroupToUpdate();
if (nextCollectionGroupToUpdate == null || hashSet.contains(nextCollectionGroupToUpdate)) {
break;
}
Logger.debug("IndexBackfiller", "Processing collection: %s", nextCollectionGroupToUpdate);
i -= writeEntriesForCollectionGroup(nextCollectionGroupToUpdate, i);
hashSet.add(nextCollectionGroupToUpdate);
}
return this.maxDocumentsToProcess - i;
}
private int writeEntriesForCollectionGroup(String str, int i) {
IndexManager indexManager = this.indexManagerOfCurrentUser.get();
LocalDocumentsView localDocumentsView = this.localDocumentsViewOfCurrentUser.get();
FieldIndex.IndexOffset minOffset = indexManager.getMinOffset(str);
LocalDocumentsResult nextDocuments = localDocumentsView.getNextDocuments(str, minOffset, i);
indexManager.updateIndexEntries(nextDocuments.getDocuments());
FieldIndex.IndexOffset newOffset = getNewOffset(minOffset, nextDocuments);
Logger.debug("IndexBackfiller", "Updating offset: %s", newOffset);
indexManager.updateCollectionGroup(str, newOffset);
return nextDocuments.getDocuments().size();
}
private FieldIndex.IndexOffset getNewOffset(FieldIndex.IndexOffset indexOffset, LocalDocumentsResult localDocumentsResult) {
Iterator<Map.Entry<DocumentKey, Document>> it = localDocumentsResult.getDocuments().iterator();
FieldIndex.IndexOffset indexOffset2 = indexOffset;
while (it.hasNext()) {
FieldIndex.IndexOffset fromDocument = FieldIndex.IndexOffset.fromDocument(it.next().getValue());
if (fromDocument.compareTo(indexOffset2) > 0) {
indexOffset2 = fromDocument;
}
}
return FieldIndex.IndexOffset.create(indexOffset2.getReadTime(), indexOffset2.getDocumentKey(), Math.max(localDocumentsResult.getBatchId(), indexOffset.getLargestBatchId()));
}
public Scheduler getScheduler() {
return this.scheduler;
}
}