Skip to content

Unify local.QueryData with the other platforms #1027

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 7 commits into from
Jul 20, 2018
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
2 changes: 1 addition & 1 deletion packages/firestore/src/local/local_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ export class LocalStore {
// any preexisting value.
const resumeToken = change.resumeToken;
if (resumeToken.length > 0) {
queryData = queryData.update({
queryData = queryData.copy({
resumeToken,
snapshotVersion: remoteEvent.snapshotVersion
});
Expand Down
20 changes: 10 additions & 10 deletions packages/firestore/src/local/query_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@ export enum QueryPurpose {
export class QueryData {
constructor(
/** The query being listened to. */
public query: Query,
readonly query: Query,
/**
* The target ID to which the query corresponds; Assigned by the
* LocalStore for user listens and by the SyncEngine for limbo watches.
*/
public targetId: TargetId,
readonly targetId: TargetId,
/** The purpose of the query. */
public purpose: QueryPurpose,
readonly purpose: QueryPurpose,
/** The latest snapshot version seen for this target. */
public snapshotVersion: SnapshotVersion = SnapshotVersion.MIN,
readonly snapshotVersion: SnapshotVersion = SnapshotVersion.MIN,
/**
* An opaque, server-assigned token that allows watching a query to be
* resumed after disconnecting without retransmitting all the data that
* matches the query. The resume token essentially identifies a point in
* time from which the server should resume sending results.
*/
public resumeToken: ProtoByteString = emptyByteString()
readonly resumeToken: ProtoByteString = emptyByteString()
) {}

/**
* Creates a new query data instance with an updated snapshot version and
* resume token.
*/
update(updated: {
resumeToken: ProtoByteString;
snapshotVersion: SnapshotVersion;
copy(overwrite: {
resumeToken?: ProtoByteString;
snapshotVersion?: SnapshotVersion;
}): QueryData {
return new QueryData(
this.query,
this.targetId,
this.purpose,
updated.snapshotVersion,
updated.resumeToken
overwrite.snapshotVersion || this.snapshotVersion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, sorry! I just noticed that this won't work. You will not be able to set snapshotVersion to 0 (SnapshotVersion.MIN) using this code. You need to explicitly check for undefined.

overwrite.resumeToken || this.resumeToken
);
}

Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/src/remote/remote_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class RemoteStore implements TargetMetadataProvider {
const queryData = this.listenTargets[targetId];
// A watched target might have been removed already.
if (queryData) {
this.listenTargets[targetId] = queryData.update({
this.listenTargets[targetId] = queryData.copy({
resumeToken: change.resumeToken,
snapshotVersion
});
Expand All @@ -424,7 +424,9 @@ export class RemoteStore implements TargetMetadataProvider {

// Clear the resume token for the query, since we're in a known mismatch
// state.
queryData.resumeToken = emptyByteString();
this.listenTargets[targetId] = queryData.copy({
resumeToken: emptyByteString()
});

// Cause a hard reset by unwatching and rewatching immediately, but
// deliberately don't send a resume token so that we get a full update.
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/test/unit/remote/remote_event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,7 @@ describe('RemoteEvent', () => {
WatchTargetChangeState.Current,
[1, 2]
);
const targets = listens(1, 2);
targets[2].purpose = QueryPurpose.LimboResolution;
const targets = { ...listens(1), ...limboListens(2) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty! I didn't know you could do this.


const event = createRemoteEvent({
snapshotVersion: 1,
Expand Down