Skip to content

Commit 36891f7

Browse files
Formatting firebase-database-collection
1 parent 72e972c commit 36891f7

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

firebase-database-collection/src/main/java/com/google/firebase/database/collection/ImmutableSortedMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public abstract class ImmutableSortedMap<K, V> implements Iterable<Map.Entry<K,
5858

5959
public ImmutableSortedMap<K, V> insertAll(ImmutableSortedMap<K, V> source) {
6060
ImmutableSortedMap<K, V> result = this;
61-
for (Map.Entry<K, V> entry: source) {
61+
for (Map.Entry<K, V> entry : source) {
6262
result = result.insert(entry.getKey(), entry.getValue());
6363
}
64-
return result;
64+
return result;
6565
}
6666

6767
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteSchema.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
import androidx.annotation.VisibleForTesting;
2727
import com.google.common.base.Preconditions;
2828
import com.google.firebase.firestore.model.ResourcePath;
29+
import com.google.firebase.firestore.util.BackgroundQueue;
2930
import com.google.firebase.firestore.util.Consumer;
31+
import com.google.firebase.firestore.util.Executors;
32+
3033
import java.util.ArrayList;
3134
import java.util.List;
3235

@@ -45,15 +48,8 @@ class SQLiteSchema {
4548
/**
4649
* The version of the schema. Increase this by one for each migration added to runMigrations
4750
* below.
48-
*
49-
* <p>TODO(index-free): The migration to schema version 9 doesn't backfill `read_time` as this
50-
* requires rewriting the RemoteDocumentCache. For index-free queries to efficiently handle
51-
* existing documents, we still need to populate read_time for all existing entries, drop the
52-
* RemoteDocumentCache or ask users to invoke `clearPersistence()` manually. If we decide to
53-
* backfill or drop the contents of the RemoteDocumentCache, we need to perform an additional
54-
* schema migration.
5551
*/
56-
static final int VERSION = 9;
52+
static final int VERSION = 10;
5753

5854
// Remove this constant and increment VERSION to enable indexing support
5955
static final int INDEXING_SUPPORT_VERSION = VERSION + 1;
@@ -74,11 +70,11 @@ class SQLiteSchema {
7470
this.db = db;
7571
}
7672

77-
void runMigrations() {
73+
int runMigrations() {
7874
runMigrations(0, VERSION);
7975
}
8076

81-
void runMigrations(int fromVersion) {
77+
int runMigrations(int fromVersion) {
8278
runMigrations(fromVersion, VERSION);
8379
}
8480

@@ -89,7 +85,9 @@ void runMigrations(int fromVersion) {
8985
* @param toVersion The version the database is migrating to. Usually VERSION, but can be
9086
* otherwise for testing.
9187
*/
92-
void runMigrations(int fromVersion, int toVersion) {
88+
int runMigrations(int fromVersion, int toVersion) {
89+
int finalVersion = fromVersion;
90+
9391
/*
9492
* New migrations should be added at the end of the series of `if` statements and should follow
9593
* the pattern. Make sure to increment `VERSION` and to read the comment below about
@@ -100,6 +98,7 @@ void runMigrations(int fromVersion, int toVersion) {
10098
createV1MutationQueue();
10199
createV1QueryCache();
102100
createV1RemoteDocumentCache();
101+
finalVersion = 1;
103102
}
104103

105104
// Migration 2 to populate the target_globals table no longer needed since migration 3
@@ -112,31 +111,49 @@ void runMigrations(int fromVersion, int toVersion) {
112111
dropV1QueryCache();
113112
createV1QueryCache();
114113
}
114+
finalVersion = 3;
115115
}
116116

117117
if (fromVersion < 4 && toVersion >= 4) {
118118
ensureTargetGlobal();
119119
addTargetCount();
120+
finalVersion = 4;
120121
}
121122

122123
if (fromVersion < 5 && toVersion >= 5) {
123124
addSequenceNumber();
125+
finalVersion = 5;
124126
}
125127

126128
if (fromVersion < 6 && toVersion >= 6) {
127129
removeAcknowledgedMutations();
130+
finalVersion = 6;
128131
}
129132

130133
if (fromVersion < 7 && toVersion >= 7) {
131134
ensureSequenceNumbers();
135+
finalVersion = 7;
132136
}
133137

134138
if (fromVersion < 8 && toVersion >= 8) {
135139
createV8CollectionParentsIndex();
140+
finalVersion = 8;
136141
}
137142

138143
if (fromVersion < 9 && toVersion >= 9) {
139144
addReadTime();
145+
finalVersion = 9;
146+
}
147+
148+
if (fromVersion < 10 && toVersion >= 10) {
149+
// Migration 10 slowly populates the read time. If no documents lack read time, we mark the migration as complete.
150+
if (!hasDocumentsWithoutReadTime()) {
151+
return 10;
152+
}
153+
154+
Executors.BACKGROUND_EXECUTOR.execute(this::populateReadTime);
155+
156+
return 9;
140157
}
141158

142159
/*
@@ -158,6 +175,10 @@ void runMigrations(int fromVersion, int toVersion) {
158175
}
159176
}
160177

178+
private void populateReadTime() {
179+
180+
}
181+
161182
/**
162183
* Used to assert that a set of tables either all exist or not. The supplied function is run if
163184
* none of the tables exist. Use this method to create a set of tables at once.

0 commit comments

Comments
 (0)