Skip to content

Commit e8972ef

Browse files
Port IndexManager APIs (#5960)
1 parent 7f95962 commit e8972ef

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed

packages/firestore/src/local/index_manager.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { Target } from '../core/target';
19+
import { DocumentKeySet, DocumentMap } from '../model/collections';
20+
import { FieldIndex, IndexOffset } from '../model/field_index';
1821
import { ResourcePath } from '../model/path';
1922

2023
import { PersistencePromise } from './persistence_promise';
@@ -50,4 +53,89 @@ export interface IndexManager {
5053
transaction: PersistenceTransaction,
5154
collectionId: string
5255
): PersistencePromise<ResourcePath[]>;
56+
57+
/**
58+
* Adds a field path index.
59+
*
60+
* Values for this index are persisted via the index backfill, which runs
61+
* asynchronously in the background. Once the first values are written,
62+
* an index can be used to serve partial results for any matching queries.
63+
* Any unindexed portion of the database will continue to be served via
64+
* collection scons.
65+
*/
66+
addFieldIndex(
67+
transaction: PersistenceTransaction,
68+
index: FieldIndex
69+
): PersistencePromise<void>;
70+
71+
/** Removes the given field index and deletes all index values. */
72+
deleteFieldIndex(
73+
transaction: PersistenceTransaction,
74+
index: FieldIndex
75+
): PersistencePromise<void>;
76+
77+
/**
78+
* Returns a list of field indexes that correspond to the specified collection
79+
* group.
80+
*
81+
* @param collectionGroup The collection group to get matching field indexes
82+
* for.
83+
* @return A collection of field indexes for the specified collection group.
84+
*/
85+
getFieldIndexes(
86+
transaction: PersistenceTransaction,
87+
collectionGroup: string
88+
): PersistencePromise<FieldIndex[]>;
89+
90+
/** Returns all configured field indexes. */
91+
getFieldIndexes(
92+
transaction: PersistenceTransaction
93+
): PersistencePromise<FieldIndex[]>;
94+
95+
/**
96+
* Returns an index that can be used to serve the provided target. Returns
97+
* `null` if no index is configured.
98+
*/
99+
getFieldIndex(
100+
transaction: PersistenceTransaction,
101+
target: Target
102+
): PersistencePromise<FieldIndex | null>;
103+
104+
/**
105+
* Returns the documents that match the given target based on the provided
106+
* index.
107+
*/
108+
getDocumentsMatchingTarget(
109+
transaction: PersistenceTransaction,
110+
fieldIndex: FieldIndex,
111+
target: Target
112+
): PersistencePromise<DocumentKeySet>;
113+
114+
/**
115+
* Returns the next collection group to update. Returns `null` if no group
116+
* exists.
117+
*/
118+
getNextCollectionGroupToUpdate(
119+
transaction: PersistenceTransaction
120+
): PersistencePromise<string | null>;
121+
122+
/**
123+
* Sets the collection group's latest read time.
124+
*
125+
* This method updates the index offset for all field indices for the
126+
* collection group and increments their sequence number. Subsequent calls to
127+
* `getNextCollectionGroupToUpdate()` will return a different collection group
128+
* (unless only one collection group is configured).
129+
*/
130+
updateCollectionGroup(
131+
transaction: PersistenceTransaction,
132+
collectionGroup: string,
133+
offset: IndexOffset
134+
): PersistencePromise<void>;
135+
136+
/** Updates the index entries for the provided documents. */
137+
updateIndexEntries(
138+
transaction: PersistenceTransaction,
139+
documents: DocumentMap
140+
): PersistencePromise<void>;
53141
}

packages/firestore/src/local/indexeddb_index_manager.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { Target } from '../core/target';
19+
import {
20+
documentKeySet,
21+
DocumentKeySet,
22+
DocumentMap
23+
} from '../model/collections';
24+
import { FieldIndex, IndexOffset } from '../model/field_index';
1825
import { ResourcePath } from '../model/path';
1926
import { debugAssert } from '../util/assert';
2027
import { immediateSuccessor } from '../util/misc';
@@ -102,6 +109,71 @@ export class IndexedDbIndexManager implements IndexManager {
102109
return parentPaths;
103110
});
104111
}
112+
113+
addFieldIndex(
114+
transaction: PersistenceTransaction,
115+
index: FieldIndex
116+
): PersistencePromise<void> {
117+
// TODO(indexing): Implement
118+
return PersistencePromise.resolve();
119+
}
120+
121+
deleteFieldIndex(
122+
transaction: PersistenceTransaction,
123+
index: FieldIndex
124+
): PersistencePromise<void> {
125+
// TODO(indexing): Implement
126+
return PersistencePromise.resolve();
127+
}
128+
129+
getDocumentsMatchingTarget(
130+
transaction: PersistenceTransaction,
131+
fieldIndex: FieldIndex,
132+
target: Target
133+
): PersistencePromise<DocumentKeySet> {
134+
// TODO(indexing): Implement
135+
return PersistencePromise.resolve(documentKeySet());
136+
}
137+
138+
getFieldIndex(
139+
transaction: PersistenceTransaction,
140+
target: Target
141+
): PersistencePromise<FieldIndex | null> {
142+
// TODO(indexing): Implement
143+
return PersistencePromise.resolve<FieldIndex | null>(null);
144+
}
145+
146+
getFieldIndexes(
147+
transaction: PersistenceTransaction,
148+
collectionGroup?: string
149+
): PersistencePromise<FieldIndex[]> {
150+
// TODO(indexing): Implement
151+
return PersistencePromise.resolve<FieldIndex[]>([]);
152+
}
153+
154+
getNextCollectionGroupToUpdate(
155+
transaction: PersistenceTransaction
156+
): PersistencePromise<string | null> {
157+
// TODO(indexing): Implement
158+
return PersistencePromise.resolve<string | null>(null);
159+
}
160+
161+
updateCollectionGroup(
162+
transaction: PersistenceTransaction,
163+
collectionGroup: string,
164+
offset: IndexOffset
165+
): PersistencePromise<void> {
166+
// TODO(indexing): Implement
167+
return PersistencePromise.resolve();
168+
}
169+
170+
updateIndexEntries(
171+
transaction: PersistenceTransaction,
172+
documents: DocumentMap
173+
): PersistencePromise<void> {
174+
// TODO(indexing): Implement
175+
return PersistencePromise.resolve();
176+
}
105177
}
106178

107179
/**

packages/firestore/src/local/memory_index_manager.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { Target } from '../core/target';
19+
import {
20+
documentKeySet,
21+
DocumentKeySet,
22+
DocumentMap
23+
} from '../model/collections';
24+
import { FieldIndex, IndexOffset } from '../model/field_index';
1825
import { ResourcePath } from '../model/path';
1926
import { debugAssert } from '../util/assert';
2027
import { SortedSet } from '../util/sorted_set';
@@ -45,6 +52,71 @@ export class MemoryIndexManager implements IndexManager {
4552
this.collectionParentIndex.getEntries(collectionId)
4653
);
4754
}
55+
56+
addFieldIndex(
57+
transaction: PersistenceTransaction,
58+
index: FieldIndex
59+
): PersistencePromise<void> {
60+
// Field indices are not supported with memory persistence.
61+
return PersistencePromise.resolve();
62+
}
63+
64+
deleteFieldIndex(
65+
transaction: PersistenceTransaction,
66+
index: FieldIndex
67+
): PersistencePromise<void> {
68+
// Field indices are not supported with memory persistence.
69+
return PersistencePromise.resolve();
70+
}
71+
72+
getDocumentsMatchingTarget(
73+
transaction: PersistenceTransaction,
74+
fieldIndex: FieldIndex,
75+
target: Target
76+
): PersistencePromise<DocumentKeySet> {
77+
// Field indices are not supported with memory persistence.
78+
return PersistencePromise.resolve(documentKeySet());
79+
}
80+
81+
getFieldIndex(
82+
transaction: PersistenceTransaction,
83+
target: Target
84+
): PersistencePromise<FieldIndex | null> {
85+
// Field indices are not supported with memory persistence.
86+
return PersistencePromise.resolve<FieldIndex | null>(null);
87+
}
88+
89+
getFieldIndexes(
90+
transaction: PersistenceTransaction,
91+
collectionGroup?: string
92+
): PersistencePromise<FieldIndex[]> {
93+
// Field indices are not supported with memory persistence.
94+
return PersistencePromise.resolve<FieldIndex[]>([]);
95+
}
96+
97+
getNextCollectionGroupToUpdate(
98+
transaction: PersistenceTransaction
99+
): PersistencePromise<string | null> {
100+
// Field indices are not supported with memory persistence.
101+
return PersistencePromise.resolve<string | null>(null);
102+
}
103+
104+
updateCollectionGroup(
105+
transaction: PersistenceTransaction,
106+
collectionGroup: string,
107+
offset: IndexOffset
108+
): PersistencePromise<void> {
109+
// Field indices are not supported with memory persistence.
110+
return PersistencePromise.resolve();
111+
}
112+
113+
updateIndexEntries(
114+
transaction: PersistenceTransaction,
115+
documents: DocumentMap
116+
): PersistencePromise<void> {
117+
// Field indices are not supported with memory persistence.
118+
return PersistencePromise.resolve();
119+
}
48120
}
49121

50122
/**

0 commit comments

Comments
 (0)