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 5 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
12 changes: 6 additions & 6 deletions packages/firestore/src/local/query_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,30 @@ 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: {
copy(updated: {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine as is, but the API contract seems kind of strange. What do you think of

copy(overwrite: {
  resumeToken?: ProtoByteString;
   snapshotVersion?: SnapshotVersion;
)

Then this could be an actual copy or a customized copy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

resumeToken: ProtoByteString;
snapshotVersion: SnapshotVersion;
}): QueryData {
Expand Down
7 changes: 5 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,10 @@ 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({
snapshotVersion: queryData.snapshotVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you follow my suggestion above, this just becomes { resumeToken: empyByteString() }.

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