2020-03-24 11:56:48 +01:00
|
|
|
import { getAllIdsIterator } from "../indexing/allIds"
|
|
|
|
import { getRecordInfo } from "../recordApi/recordInfo"
|
|
|
|
import { isTopLevelIndex } from "./hierarchy"
|
|
|
|
import { joinKey } from "../common"
|
|
|
|
import { initialiseIndex } from "../indexing/initialiseIndex"
|
|
|
|
|
|
|
|
export const initialiseNewIndex = async (app, indexNode) => {
|
|
|
|
if (isTopLevelIndex(indexNode)) {
|
|
|
|
await initialiseIndex(app.datastore, "/", indexNode)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const iterate = await getAllIdsIterator(app)(indexNode.parent().nodeKey())
|
|
|
|
let iterateResult = await iterate()
|
|
|
|
while (!iterateResult.done) {
|
|
|
|
const { result } = iterateResult
|
|
|
|
for (const id of result.ids) {
|
|
|
|
const recordKey = joinKey(result.collectionKey, id)
|
|
|
|
await initialiseIndex(
|
2020-03-27 17:58:32 +01:00
|
|
|
app.datastore,
|
2020-03-24 11:56:48 +01:00
|
|
|
getRecordInfo(app.hierarchy, recordKey).dir,
|
2020-03-27 17:58:32 +01:00
|
|
|
indexNode
|
|
|
|
)
|
2020-03-24 11:56:48 +01:00
|
|
|
}
|
|
|
|
iterateResult = await iterate()
|
|
|
|
}
|
2020-03-27 17:58:32 +01:00
|
|
|
}
|