|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2023 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { User } from '../auth/user'; |
| 19 | +import { DatabaseId } from '../core/database_info'; |
| 20 | +import { IndexedDbIndexManager } from '../local/indexeddb_index_manager'; |
| 21 | +import { IndexedDbPersistence } from '../local/indexeddb_persistence'; |
| 22 | +import { LocalDocumentsView } from '../local/local_documents_view'; |
| 23 | +import { LruParams } from '../local/lru_garbage_collector'; |
| 24 | +import { QueryEngine } from '../local/query_engine'; |
| 25 | +import { getDocument, getWindow } from '../platform/dom'; |
| 26 | +import { JsonProtoSerializer } from '../remote/serializer'; |
| 27 | +import { AsyncQueueImpl } from '../util/async_queue_impl'; |
| 28 | +import { AutoId } from '../util/misc'; |
| 29 | + |
| 30 | +export function runPersistentCacheIndexPerformanceExperiment( |
| 31 | + log: (...args: unknown[]) => unknown |
| 32 | +): void { |
| 33 | + const { queryEngine } = createTestObjects(); |
| 34 | + log('Created QueryEngine', queryEngine); |
| 35 | +} |
| 36 | + |
| 37 | +interface TestObjects { |
| 38 | + queryEngine: QueryEngine; |
| 39 | +} |
| 40 | + |
| 41 | +function createTestObjects(): TestObjects { |
| 42 | + const databaseId = new DatabaseId(/*projectId=*/ AutoId.newId()); |
| 43 | + const user = new User(/*uid=*/ null); |
| 44 | + const persistence = new IndexedDbPersistence( |
| 45 | + /*allowTabSynchronization=*/ false, |
| 46 | + /*persistenceKey=*/ AutoId.newId(), |
| 47 | + /*clientId=*/ AutoId.newId(), |
| 48 | + /*lruParams=*/ LruParams.DISABLED, |
| 49 | + /*queue=*/ new AsyncQueueImpl(), |
| 50 | + /*window=*/ getWindow(), |
| 51 | + /*document=*/ getDocument(), |
| 52 | + /*serializer=*/ new JsonProtoSerializer( |
| 53 | + databaseId, |
| 54 | + /*useProto3Json=*/ true |
| 55 | + ), |
| 56 | + /*sequenceNumberSyncer=*/ { |
| 57 | + writeSequenceNumber(_: unknown): void {}, |
| 58 | + sequenceNumberHandler: null |
| 59 | + }, |
| 60 | + /*forceOwningTab=*/ false |
| 61 | + ); |
| 62 | + |
| 63 | + const remoteDocumentCache = persistence.getRemoteDocumentCache(); |
| 64 | + const indexManager = new IndexedDbIndexManager(user, databaseId); |
| 65 | + const mutationQueue = persistence.getMutationQueue(user, indexManager); |
| 66 | + const documentOverlayCache = persistence.getDocumentOverlayCache(user); |
| 67 | + const localDocumentView = new LocalDocumentsView( |
| 68 | + remoteDocumentCache, |
| 69 | + mutationQueue, |
| 70 | + documentOverlayCache, |
| 71 | + indexManager |
| 72 | + ); |
| 73 | + const queryEngine = new QueryEngine(); |
| 74 | + queryEngine.initialize(localDocumentView, indexManager); |
| 75 | + |
| 76 | + return { queryEngine }; |
| 77 | +} |
0 commit comments