@@ -1652,7 +1652,8 @@ export class Stack {
1652
1652
this . q . query = { }
1653
1653
}
1654
1654
1655
- this . q . referenceDepth = this . q . referenceDepth || this . contentStore . referenceDepth
1655
+ // tslint:disable-next-line: max-line-length
1656
+ this . q . referenceDepth = ( typeof this . q . referenceDepth === 'number' ) ? this . q . referenceDepth : this . contentStore . referenceDepth
1656
1657
1657
1658
if ( this . internal . only ) {
1658
1659
this . internal . projections = this . internal . only
@@ -1780,7 +1781,6 @@ export class Stack {
1780
1781
} )
1781
1782
}
1782
1783
1783
- // console.log('this.internal.includeSchema', this.internal.includeSchema)
1784
1784
if ( this . internal . includeSchema ) {
1785
1785
output . content_type = await this . db . collection ( getCollectionName ( {
1786
1786
content_type_uid : this . types . content_types ,
@@ -1898,7 +1898,6 @@ export class Stack {
1898
1898
$or : [ ] ,
1899
1899
} // reference field paths
1900
1900
const shelf = [ ] // a mapper object, that holds pointer to the original element
1901
-
1902
1901
// iterate over each path in the entries and fetch the references
1903
1902
// while fetching, keep track of their location
1904
1903
for ( let i = 0 , j = paths . length ; i < j ; i ++ ) {
@@ -2023,12 +2022,24 @@ export class Stack {
2023
2022
2024
2023
for ( let i = 0 , j = oldShelf . length ; i < j ; i ++ ) {
2025
2024
const element : IShelf = oldShelf [ i ]
2025
+ let flag = true
2026
2026
for ( let k = 0 , l = result . length ; k < l ; k ++ ) {
2027
2027
if ( result [ k ] . uid === element . uid ) {
2028
2028
element . path [ element . position ] = result [ k ]
2029
+ flag = false
2029
2030
break
2030
2031
}
2031
2032
}
2033
+
2034
+ if ( flag ) {
2035
+ for ( let e = 0 , f = oldShelf [ i ] . path . length ; e < f ; e ++ ) {
2036
+ // tslint:disable-next-line: max-line-length
2037
+ if ( oldShelf [ i ] . path [ e ] . hasOwnProperty ( '_content_type_uid' ) && Object . keys ( oldShelf [ i ] . path [ e ] ) . length === 2 ) {
2038
+ ( oldShelf [ i ] . path as any ) . splice ( e , 1 )
2039
+ break
2040
+ }
2041
+ }
2042
+ }
2032
2043
}
2033
2044
2034
2045
// GC to avoid mem leaks!
@@ -2083,13 +2094,12 @@ export class Stack {
2083
2094
const includePath = currentInclude [ i ]
2084
2095
// tslint:disable-next-line: forin
2085
2096
for ( const path in entryReferences ) {
2086
- const idx = includePath . indexOf ( path )
2087
- // tslint:disable-next-line: no-bitwise
2088
- if ( ~ idx ) {
2097
+ const subStr = includePath . slice ( 0 , path . length )
2098
+ if ( subStr === path ) {
2089
2099
let subPath
2090
2100
// Its the complete path!! Hurrah!
2091
2101
if ( path . length !== includePath . length ) {
2092
- subPath = includePath . slice ( 0 , path . length )
2102
+ subPath = subStr
2093
2103
pendingPath . push ( includePath . slice ( path . length + 1 ) )
2094
2104
} else {
2095
2105
subPath = includePath
@@ -2100,8 +2110,7 @@ export class Stack {
2100
2110
_content_type_uid : this . types . content_types ,
2101
2111
uid : entryReferences [ path ] ,
2102
2112
} )
2103
- } else {
2104
-
2113
+ } else if ( entryReferences [ path ] . length ) {
2105
2114
entryReferences [ path ] . forEach ( ( contentTypeUid ) => {
2106
2115
schemasReferred . push ( {
2107
2116
_content_type_uid : this . types . content_types ,
@@ -2230,13 +2239,26 @@ export class Stack {
2230
2239
2231
2240
for ( let i = 0 , j = oldObjectPointerList . length ; i < j ; i ++ ) {
2232
2241
const element : IShelf = oldObjectPointerList [ i ]
2242
+ let flag = true
2233
2243
for ( let k = 0 , l = result . length ; k < l ; k ++ ) {
2234
2244
if ( result [ k ] . uid === element . uid ) {
2235
2245
element . path [ element . position ] = result [ k ]
2246
+ flag = false
2236
2247
break
2237
2248
}
2238
2249
}
2250
+
2251
+ if ( flag ) {
2252
+ for ( let e = 0 , f = oldObjectPointerList [ i ] . path . length ; e < f ; e ++ ) {
2253
+ // tslint:disable-next-line: max-line-length
2254
+ if ( oldObjectPointerList [ i ] . path [ e ] . hasOwnProperty ( '_content_type_uid' ) && Object . keys ( oldObjectPointerList [ i ] . path [ e ] ) . length === 2 ) {
2255
+ ( oldObjectPointerList [ i ] . path as any ) . splice ( e , 1 )
2256
+ break
2257
+ }
2258
+ }
2259
+ }
2239
2260
}
2261
+
2240
2262
// GC to avoid mem leaks!
2241
2263
oldObjectPointerList = null
2242
2264
0 commit comments