@@ -198,16 +198,16 @@ async function alterHistoryNext(objToUpdate, newNextID) {
198198async function getAllVersions ( obj ) {
199199 let ls_versions
200200 let primeID = obj ?. __rerum . history . prime
201- let rootObj = ( primeID === "root" )
202- ? //The obj passed in is root. So it is the rootObj we need.
203- JSON . parse ( JSON . stringify ( obj ) )
204- : //The obj passed in knows the ID of root, grab it from Mongo
205- await db . findOne ( { "@id" : primeID } )
206- /**
207- * Note that if you attempt the following code, it will cause Cannot convert undefined or null to object in getAllVersions.
208- * rootObj = await db.findOne({"$or":[{"_id": primeID}, {"__rerum.slug": primeID}]} )
209- * This is the because some of the @ids have different RERUM URL patterns on them.
210- **/
201+ let rootObj
202+ if ( primeID === " root" ) {
203+ //The obj passed in is root. So it is the rootObj we need.
204+ rootObj = JSON . parse ( JSON . stringify ( obj ) )
205+ } else {
206+ //The obj passed in knows the ID of root, grab it from Mongo
207+ //Use _id for indexed query performance instead of @id
208+ const primeHexId = parseDocumentID ( primeID )
209+ rootObj = await db . findOne ( { "$or" : [ { "_id" : primeHexId } , { "__rerum.slug" : primeHexId } ] } )
210+ }
211211 //All the children of this object will have its @id in __rerum.history.prime
212212 ls_versions = await db . find ( { "__rerum.history.prime" : rootObj [ '@id' ] } ) . toArray ( )
213213 //The root object is a version, prepend it in
0 commit comments