@ossy/event-store 3.6.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/package.json +2 -2
- package/src/ensure-indexes.js +6 -0
package/README.md
CHANGED
|
@@ -155,13 +155,20 @@ import { Mongo } from '@ossy/event-store'
|
|
|
155
155
|
await Mongo.connect(process.env.DB_URL)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
Recommended indexes
|
|
158
|
+
Recommended indexes (created at startup by `ensureEventStoreIndexes`):
|
|
159
159
|
|
|
160
160
|
```js
|
|
161
|
+
// eventstore
|
|
161
162
|
{ resourceId: 1, version: 1 } // stream queries
|
|
162
|
-
|
|
163
|
+
|
|
164
|
+
// aggregates
|
|
165
|
+
{ id: 1 } // snapshot get-by-id
|
|
166
|
+
{ type: 1, 'state.email': 1 } // user lookup (sparse)
|
|
167
|
+
{ 'state.belongsTo': 1, 'state.location': 1 } // folder list/search (sparse)
|
|
163
168
|
```
|
|
164
169
|
|
|
170
|
+
`{ type: 1, event: 1 }` on `eventstore` is still useful for projection replay / task triggers but is not created automatically.
|
|
171
|
+
|
|
165
172
|
---
|
|
166
173
|
|
|
167
174
|
## Testing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/event-store",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Ossy Event Store — Aggregate, EventStore, and MongoDB client",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"src"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "622d97535abad08415963405ace2f5aaaecd7ca4"
|
|
41
41
|
}
|
package/src/ensure-indexes.js
CHANGED
|
@@ -9,6 +9,8 @@ let ensured = false
|
|
|
9
9
|
* Ensure MongoDB indexes required for aggregate/event-stream reads.
|
|
10
10
|
* Without `{ resourceId, version }` on `eventstore`, every `getResourceStream`
|
|
11
11
|
* call scans the full collection — sign-up and changestream rebuilds deadlock under load.
|
|
12
|
+
* Without `{ state.belongsTo, state.location }` on `aggregates`, folder list/search
|
|
13
|
+
* examines the whole collection, including audit snapshots that are not in any folder.
|
|
12
14
|
*/
|
|
13
15
|
export async function ensureEventStoreIndexes () {
|
|
14
16
|
if (ensured) return
|
|
@@ -29,6 +31,10 @@ export async function ensureEventStoreIndexes () {
|
|
|
29
31
|
{ type: 1, 'state.email': 1 },
|
|
30
32
|
{ name: 'type_state_email', background: true, sparse: true },
|
|
31
33
|
)
|
|
34
|
+
await aggregates.createIndex(
|
|
35
|
+
{ 'state.belongsTo': 1, 'state.location': 1 },
|
|
36
|
+
{ name: 'state_belongsTo_location', background: true, sparse: true },
|
|
37
|
+
)
|
|
32
38
|
})
|
|
33
39
|
|
|
34
40
|
ensured = true
|