-
Notifications
You must be signed in to change notification settings - Fork 625
Index-Free: Using readTime instead of updateTime #686
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.google.firebase.firestore.model.Document; | ||
import com.google.firebase.firestore.model.DocumentKey; | ||
import com.google.firebase.firestore.model.MaybeDocument; | ||
import com.google.firebase.firestore.model.SnapshotVersion; | ||
import java.util.Map; | ||
|
||
/** | ||
|
@@ -40,8 +41,9 @@ interface RemoteDocumentCache { | |
* for the key, it will be replaced. | ||
* | ||
* @param maybeDocument A Document or NoDocument to put in the cache. | ||
* @param readTime The time at which the document was read or committed. | ||
*/ | ||
void add(MaybeDocument maybeDocument); | ||
void add(MaybeDocument maybeDocument, SnapshotVersion readTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dumb question: why not make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was the road I went down on at first - it generates a significant amount of changes to plumb through a value that is only ever read directly at source. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sort of surprised there are that many changes. Did you happen to commit it so I can see? For example: all our tests could use the same snapshot for both versions by default and only specify a second timestamp when the difference really matters. That means nearly all tests would be unaffected. Oh, maybe the issue is that the read_time comes from the TargetChange and is not intrinsically a part of the document? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are at least two additional challenges:
I never actually got as far as to see how we would construct the individual documents. By exposing the read time only as an input to the RemoteDocumentCache there are only two callsites that need changing, which won me over. |
||
|
||
/** Removes the cached entry for the given key (no-op if no entry exists). */ | ||
void remove(DocumentKey documentKey); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import static com.google.firebase.firestore.testutil.TestUtil.map; | ||
import static com.google.firebase.firestore.testutil.TestUtil.path; | ||
import static com.google.firebase.firestore.testutil.TestUtil.values; | ||
import static com.google.firebase.firestore.testutil.TestUtil.version; | ||
import static java.util.Arrays.asList; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
@@ -32,6 +33,7 @@ | |
import com.google.firebase.firestore.model.DocumentKey; | ||
import com.google.firebase.firestore.model.MaybeDocument; | ||
import com.google.firebase.firestore.model.NoDocument; | ||
import com.google.firebase.firestore.model.SnapshotVersion; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
@@ -134,7 +136,7 @@ public void testSetAndReadLotsOfDocuments() { | |
public void testSetAndReadDeletedDocument() { | ||
String path = "a/b"; | ||
NoDocument deletedDoc = deletedDoc(path, 42); | ||
add(deletedDoc); | ||
add(deletedDoc, version(42)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these tests use identical versions for the update_time and read_time which means we could have gotten these reversed and won't see it. Could you add a test that verifies read time doesn't get crossed with update time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will become easier to add this test when #617 lands (which should be the next PR). I added a TODO for now and will resolve it when we gain the ability to exclude documents by read time. |
||
assertEquals(deletedDoc, get(path)); | ||
} | ||
|
||
|
@@ -144,7 +146,7 @@ public void testSetDocumentToNewValue() { | |
Document written = addTestDocumentAtPath(path); | ||
|
||
Document newDoc = doc(path, 57, map("data", 5)); | ||
add(newDoc); | ||
add(newDoc, version(57)); | ||
|
||
assertNotEquals(written, newDoc); | ||
assertEquals(newDoc, get(path)); | ||
|
@@ -182,12 +184,14 @@ public void testDocumentsMatchingQuery() { | |
|
||
private Document addTestDocumentAtPath(String path) { | ||
Document doc = doc(path, 42, map("data", 2)); | ||
add(doc); | ||
add(doc, version(42)); | ||
return doc; | ||
} | ||
|
||
private void add(MaybeDocument doc) { | ||
persistence.runTransaction("add entry", () -> remoteDocumentCache.add(doc)); | ||
// TODO(mrschmidt): Add a test uses different update and read times and verifies that we correctly | ||
// filter by read time | ||
private void add(MaybeDocument doc, SnapshotVersion readTime) { | ||
persistence.runTransaction("add entry", () -> remoteDocumentCache.add(doc, readTime)); | ||
} | ||
|
||
@Nullable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the real only benefit of the changes in this file (and the additional memory-overhead) is that we can run the LocalStore tests with IndexFree queries both against the MemoryRemoteDocumentCache and the SQLiteRemoteDocumentCache. We need to match the filter logic to be able to compare row read counts.