Skip to content

Revert "Add update_time to SQLRemoteDocumentCache schema" #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.google.firebase.firestore.util.Assert.hardAssert;

import androidx.annotation.Nullable;
import com.google.firebase.Timestamp;
import com.google.firebase.database.collection.ImmutableSortedMap;
import com.google.firebase.firestore.core.Query;
import com.google.firebase.firestore.model.Document;
Expand Down Expand Up @@ -52,18 +51,13 @@ final class SQLiteRemoteDocumentCache implements RemoteDocumentCache {
@Override
public void add(MaybeDocument maybeDocument) {
String path = pathForKey(maybeDocument.getKey());
Timestamp timestamp = maybeDocument.getVersion().getTimestamp();
MessageLite message = serializer.encodeMaybeDocument(maybeDocument);

statsCollector.recordRowsWritten(STATS_TAG, 1);

db.execute(
"INSERT OR REPLACE INTO remote_documents "
+ "(path, update_time_seconds, update_time_nanos, contents) "
+ "VALUES (?, ?, ?, ?)",
"INSERT OR REPLACE INTO remote_documents (path, contents) VALUES (?, ?)",
path,
timestamp.getSeconds(),
timestamp.getNanoseconds(),
message.toByteArray());

db.getIndexManager().addToCollectionParentIndex(maybeDocument.getKey().getPath().popLast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,8 @@ class SQLiteSchema {
/**
* The version of the schema. Increase this by one for each migration added to runMigrations
* below.
*
* <p>TODO(index-free): The migration to schema version 9 doesn't backfill `update_time` as this
* requires rewriting the RemoteDocumentCache. For index-free queries to efficiently handle
* existing documents, we still need to populate update_time for all existing entries, drop the
* RemoteDocumentCache or ask users to invoke `clearPersistence()` manually. If we decide to
* backfill or drop the contents of the RemoteDocumentCache, we need to perform an additional
* schema migration.
*/
static final int VERSION = 9;

static final int VERSION = 8;
// Remove this constant and increment VERSION to enable indexing support
static final int INDEXING_SUPPORT_VERSION = VERSION + 1;

Expand Down Expand Up @@ -135,10 +127,6 @@ void runMigrations(int fromVersion, int toVersion) {
createV8CollectionParentsIndex();
}

if (fromVersion < 9 && toVersion >= 9) {
addUpdateTime();
}

/*
* Adding a new migration? READ THIS FIRST!
*
Expand Down Expand Up @@ -363,16 +351,6 @@ private void addSequenceNumber() {
}
}

private void addUpdateTime() {
if (!tableContainsColumn("remote_documents", "update_time_seconds")) {
hardAssert(
!tableContainsColumn("remote_documents", "update_time_nanos"),
"Table contained update_time_seconds, but is missing update_time_nanos");
db.execSQL("ALTER TABLE remote_documents ADD COLUMN update_time_seconds INTEGER");
db.execSQL("ALTER TABLE remote_documents ADD COLUMN update_time_nanos INTEGER");
}
}

/**
* Ensures that each entry in the remote document cache has a corresponding sentinel row. Any
* entries that lack a sentinel row are given one with the sequence number set to the highest
Expand Down