Skip to content

Merging Master into Multi-Tab #1078

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 5 commits into from
Aug 1, 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
3 changes: 3 additions & 0 deletions packages/auth/src/error_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fireauth.authenum.Error = {
INVALID_PASSWORD: 'wrong-password',
INVALID_PERSISTENCE: 'invalid-persistence-type',
INVALID_PHONE_NUMBER: 'invalid-phone-number',
INVALID_PROVIDER_ID: 'invalid-provider-id',
INVALID_RECIPIENT_EMAIL: 'invalid-recipient-email',
INVALID_SENDER: 'invalid-sender',
INVALID_SESSION_INFO: 'invalid-verification-id',
Expand Down Expand Up @@ -294,6 +295,8 @@ fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PHONE_NUMBER] =
'phone number in a format that can be parsed into E.164 format. E.164 ' +
'phone numbers are written in the format [+][country code][subscriber ' +
'number including area code].';
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_PROVIDER_ID] =
'The specified provider ID is invalid.';
fireauth.AuthError.MESSAGES_[fireauth.authenum.Error.INVALID_RECIPIENT_EMAIL] =
'The email corresponding to this action failed to send as the provided ' +
'recipient email address is invalid.';
Expand Down
5 changes: 5 additions & 0 deletions packages/auth/src/rpchandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ fireauth.RpcHandler.ServerError = {
INVALID_OOB_CODE: 'INVALID_OOB_CODE',
INVALID_PASSWORD: 'INVALID_PASSWORD',
INVALID_PHONE_NUMBER: 'INVALID_PHONE_NUMBER',
INVALID_PROVIDER_ID: 'INVALID_PROVIDER_ID',
INVALID_RECIPIENT_EMAIL: 'INVALID_RECIPIENT_EMAIL',
INVALID_SENDER: 'INVALID_SENDER',
INVALID_SESSION_INFO: 'INVALID_SESSION_INFO',
Expand Down Expand Up @@ -2244,6 +2245,10 @@ fireauth.RpcHandler.getDeveloperError_ =
errorMap[fireauth.RpcHandler.ServerError.MISSING_OOB_CODE] =
fireauth.authenum.Error.INTERNAL_ERROR;

// Get Auth URI errors:
errorMap[fireauth.RpcHandler.ServerError.INVALID_PROVIDER_ID] =
fireauth.authenum.Error.INVALID_PROVIDER_ID;

// Operations that require ID token in request:
errorMap[fireauth.RpcHandler.ServerError.CREDENTIAL_TOO_OLD_LOGIN_AGAIN] =
fireauth.authenum.Error.CREDENTIAL_TOO_OLD_LOGIN_AGAIN;
Expand Down
24 changes: 24 additions & 0 deletions packages/auth/test/rpchandler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5268,6 +5268,30 @@ function testGetAuthUri_success() {
}


/**
* Tests server side getAuthUri error.
*/
function testGetAuthUri_caughtServerError() {
var expectedUrl = 'https://www.googleapis.com/identitytoolkit/v3/relyin' +
'gparty/createAuthUri?key=apiKey';
var requestBody = {
'providerId': 'abc.com',
'continueUri': 'http://localhost/widget',
'customParameter': {}
};
var errorMap = {};
// All related server errors for getAuthUri.
errorMap[fireauth.RpcHandler.ServerError.INVALID_PROVIDER_ID] =
fireauth.authenum.Error.INVALID_PROVIDER_ID;

assertServerErrorsAreHandled(function() {
return rpcHandler.getAuthUri(
'abc.com',
'http://localhost/widget');
}, errorMap, expectedUrl, requestBody);
}


/**
* Tests successful getAuthUri request with Google provider and sessionId.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Unreleased
- [changed] Improved how Firestore handles idle queries to reduce the cost of
re-listening within 30 minutes.
- [changed] Improved offline performance with many outstanding writes.

# 0.6.0
- [fixed] Fixed an issue where queries returned fewer results than they should,
caused by documents that were cached as deleted when they should not have
been (firebase/firebase-ios-sdk#1548). Because some cache data is cleared,
Expand Down
14 changes: 1 addition & 13 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
MutationBatchState,
OnlineState,
OnlineStateSource,
ProtoByteString,
TargetId
} from './types';
import {
Expand Down Expand Up @@ -88,12 +87,6 @@ class QueryView {
* stream to identify this query.
*/
public targetId: TargetId,
/**
* An identifier from the datastore backend that indicates the last state
* of the results that was received. This can be used to indicate where
* to continue receiving new doc changes for the query.
*/
public resumeToken: ProtoByteString,
/**
* The view is responsible for computing the final merged truth of what
* docs are in the query. It gets notified of local and remote changes,
Expand Down Expand Up @@ -274,12 +267,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
'applyChanges for new view should always return a snapshot'
);

const data = new QueryView(
query,
queryData.targetId,
queryData.resumeToken,
view
);
const data = new QueryView(query, queryData.targetId, view);
this.queryViewsByQuery.set(query, data);
this.queryViewsByTarget[queryData.targetId] = data;
return viewChange.snapshot!;
Expand Down
122 changes: 86 additions & 36 deletions packages/firestore/src/local/indexeddb_mutation_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Timestamp } from '../api/timestamp';
import { User } from '../auth/user';
import { Query } from '../core/query';
import { BatchId, ProtoByteString } from '../core/types';
import { DocumentKeySet } from '../model/collections';
import { DocumentKey } from '../model/document_key';
import { Mutation } from '../model/mutation';
import { BATCHID_UNKNOWN, MutationBatch } from '../model/mutation_batch';
Expand All @@ -40,8 +41,8 @@ import { LocalSerializer } from './local_serializer';
import { MutationQueue } from './mutation_queue';
import { PersistenceTransaction } from './persistence';
import { PersistencePromise } from './persistence_promise';
import { SimpleDb, SimpleDbStore } from './simple_db';
import { DocumentKeySet } from '../model/collections';
import { SimpleDbStore } from './simple_db';
import { IndexedDbPersistence } from './indexeddb_persistence';

/** A mutation queue for a specific user, backed by IndexedDB. */
export class IndexedDbMutationQueue implements MutationQueue {
Expand Down Expand Up @@ -342,6 +343,50 @@ export class IndexedDbMutationQueue implements MutationQueue {
.next(() => results);
}

getAllMutationBatchesAffectingDocumentKeys(
transaction: PersistenceTransaction,
documentKeys: DocumentKeySet
): PersistencePromise<MutationBatch[]> {
let uniqueBatchIDs = new SortedSet<BatchId>(primitiveComparator);

const promises: Array<PersistencePromise<void>> = [];
documentKeys.forEach(documentKey => {
const indexStart = DbDocumentMutation.prefixForPath(
this.userId,
documentKey.path
);
const range = IDBKeyRange.lowerBound(indexStart);

const promise = documentMutationsStore(transaction).iterate(
{ range },
(indexKey, _, control) => {
const [userID, encodedPath, batchID] = indexKey;

// Only consider rows matching exactly the specific key of
// interest. Note that because we order by path first, and we
// order terminators before path separators, we'll encounter all
// the index rows for documentKey contiguously. In particular, all
// the rows for documentKey will occur before any rows for
// documents nested in a subcollection beneath documentKey so we
// can stop as soon as we hit any such row.
const path = EncodedResourcePath.decode(encodedPath);
if (userID !== this.userId || !documentKey.path.isEqual(path)) {
control.done();
return;
}

uniqueBatchIDs = uniqueBatchIDs.add(batchID);
}
);

promises.push(promise);
});

return PersistencePromise.waitFor(promises).next(() =>
this.lookupMutationBatches(transaction, uniqueBatchIDs)
);
}

getAllMutationBatchesAffectingQuery(
transaction: PersistenceTransaction,
query: Query
Expand Down Expand Up @@ -393,34 +438,39 @@ export class IndexedDbMutationQueue implements MutationQueue {
}
uniqueBatchIDs = uniqueBatchIDs.add(batchID);
})
.next(() => {
const results: MutationBatch[] = [];
const promises: Array<PersistencePromise<void>> = [];
// TODO(rockwood): Implement this using iterate.
uniqueBatchIDs.forEach(batchId => {
promises.push(
mutationsStore(transaction)
.get(batchId)
.next(mutation => {
if (!mutation) {
fail(
'Dangling document-mutation reference found, ' +
'which points to ' +
batchId
);
}
assert(
mutation.userId === this.userId,
`Unexpected user '${
mutation.userId
}' for mutation batch ${batchId}`
);
results.push(this.serializer.fromDbMutationBatch(mutation!));
})
);
});
return PersistencePromise.waitFor(promises).next(() => results);
});
.next(() => this.lookupMutationBatches(transaction, uniqueBatchIDs));
}

private lookupMutationBatches(
transaction: PersistenceTransaction,
batchIDs: SortedSet<BatchId>
): PersistencePromise<MutationBatch[]> {
const results: MutationBatch[] = [];
const promises: Array<PersistencePromise<void>> = [];
// TODO(rockwood): Implement this using iterate.
batchIDs.forEach(batchId => {
promises.push(
mutationsStore(transaction)
.get(batchId)
.next(mutation => {
if (mutation === null) {
fail(
'Dangling document-mutation reference found, ' +
'which points to ' +
batchId
);
}
assert(
mutation.userId === this.userId,
`Unexpected user '${
mutation.userId
}' for mutation batch ${batchId}`
);
results.push(this.serializer.fromDbMutationBatch(mutation!));
})
);
});
return PersistencePromise.waitFor(promises).next(() => results);
}

removeMutationBatches(
Expand Down Expand Up @@ -567,7 +617,7 @@ function convertStreamToken(token: ProtoByteString): string {
function mutationsStore(
txn: PersistenceTransaction
): SimpleDbStore<DbMutationBatchKey, DbMutationBatch> {
return SimpleDb.getStore<DbMutationBatchKey, DbMutationBatch>(
return IndexedDbPersistence.getStore<DbMutationBatchKey, DbMutationBatch>(
txn,
DbMutationBatch.store
);
Expand All @@ -579,10 +629,10 @@ function mutationsStore(
function documentMutationsStore(
txn: PersistenceTransaction
): SimpleDbStore<DbDocumentMutationKey, DbDocumentMutation> {
return SimpleDb.getStore<DbDocumentMutationKey, DbDocumentMutation>(
txn,
DbDocumentMutation.store
);
return IndexedDbPersistence.getStore<
DbDocumentMutationKey,
DbDocumentMutation
>(txn, DbDocumentMutation.store);
}

/**
Expand All @@ -591,7 +641,7 @@ function documentMutationsStore(
function mutationQueuesStore(
txn: PersistenceTransaction
): SimpleDbStore<DbMutationQueueKey, DbMutationQueue> {
return SimpleDb.getStore<DbMutationQueueKey, DbMutationQueue>(
return IndexedDbPersistence.getStore<DbMutationQueueKey, DbMutationQueue>(
txn,
DbMutationQueue.store
);
Expand Down
Loading