Reuse document indexes in D&D normalization
This commit is contained in:
@@ -156,28 +156,25 @@ func planFromResponse(doc *source.SourceDocument, response chunkResponse) (sourc
|
||||
return source.ChunkPlan{}, fmt.Errorf("scenes must not be empty")
|
||||
}
|
||||
|
||||
unitIndexes := make(map[int]int, len(doc.Units))
|
||||
for i, unit := range doc.Units {
|
||||
unitIndexes[unit.ID] = i
|
||||
}
|
||||
index := source.NewDocumentIndex(doc)
|
||||
|
||||
ranges := make([]source.ChunkRange, 0, len(response.Scenes))
|
||||
previousEnd := -1
|
||||
for i, scene := range response.Scenes {
|
||||
startUnitID, err := shared.ResolveUnitID(doc, "start_unit_id", scene.StartUnitID)
|
||||
startUnitID, err := shared.ResolveUnitID(index, "start_unit_id", scene.StartUnitID)
|
||||
if err != nil {
|
||||
return source.ChunkPlan{}, fmt.Errorf("scene[%d] %w", i, err)
|
||||
}
|
||||
endUnitID, err := shared.ResolveUnitID(doc, "end_unit_id", scene.EndUnitID)
|
||||
endUnitID, err := shared.ResolveUnitID(index, "end_unit_id", scene.EndUnitID)
|
||||
if err != nil {
|
||||
return source.ChunkPlan{}, fmt.Errorf("scene[%d] %w", i, err)
|
||||
}
|
||||
|
||||
startIndex, ok := unitIndexes[startUnitID]
|
||||
startIndex, ok := index.Position(startUnitID)
|
||||
if !ok {
|
||||
return source.ChunkPlan{}, fmt.Errorf("scene[%d] start_unit_id %d was not found", i, startUnitID)
|
||||
}
|
||||
endIndex, ok := unitIndexes[endUnitID]
|
||||
endIndex, ok := index.Position(endUnitID)
|
||||
if !ok {
|
||||
return source.ChunkPlan{}, fmt.Errorf("scene[%d] end_unit_id %d was not found", i, endUnitID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user