Skip to content

Commit

Permalink
.include() and referenceDepth bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iyerrama29 committed Jul 27, 2019
1 parent f3db078 commit e16480d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
33 changes: 28 additions & 5 deletions dist/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,8 @@ class Stack {
const keys = Object.keys(this.contentStore.projections);
this.q.except = keys;
}
this.q.referenceDepth = this.q.referenceDepth || this.contentStore.referenceDepth;
this.q.referenceDepth = (typeof this.q.referenceDepth === 'number') ? this.q.referenceDepth : this.contentStore
.referenceDepth;
return {
filePath,
key,
Expand Down Expand Up @@ -1126,12 +1127,23 @@ class Stack {
eQuery = null;
for (let i = 0, j = oldShelf.length; i < j; i++) {
const element = oldShelf[i];
let flag = true;
for (let k = 0, l = result.docs.length; k < l; k++) {
if (result.docs[k].uid === element.uid) {
element.path[element.position] = result.docs[k];
flag = false;
break;
}
}
if (flag) {
for (let e = 0, f = oldShelf[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldShelf[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldShelf[i].path[e]).length === 2) {
oldShelf[i].path.splice(e, 1);
break;
}
}
}
}
// GC to avoid mem leaks!
oldShelf = null;
Expand Down Expand Up @@ -1187,12 +1199,12 @@ class Stack {
const includePath = currentInclude[i];
// tslint:disable-next-line: forin
for (const path in entryReferences) {
const idx = includePath.indexOf(path);
if (~idx) {
const subStr = includePath.slice(0, path.length);
if (subStr === path) {
let subPath;
// Its the complete path!! Hurrah!
if (path.length !== includePath.length) {
subPath = includePath.slice(0, path.length);
subPath = subStr;
pendingPath.push(includePath.slice(path.length + 1));
}
else {
Expand All @@ -1204,7 +1216,7 @@ class Stack {
uid: entryReferences[path],
});
}
else {
else if (entryReferences[path].length) {
entryReferences[path].forEach((contentTypeUid) => {
schemasReferred.push({
_content_type_uid: this.types.content_types,
Expand Down Expand Up @@ -1436,12 +1448,23 @@ class Stack {
oldEntryQueries = null;
for (let i = 0, j = oldObjectPointerList.length; i < j; i++) {
const element = oldObjectPointerList[i];
let flag = true;
for (let k = 0, l = result.docs.length; k < l; k++) {
if (result.docs[k].uid === element.uid) {
element.path[element.position] = result.docs[k];
flag = false;
break;
}
}
if (flag) {
for (let e = 0, f = oldObjectPointerList[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldObjectPointerList[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldObjectPointerList[i].path[e]).length === 2) {
oldObjectPointerList[i].path.splice(e, 1);
break;
}
}
}
}
// GC to avoid mem leaks!
oldObjectPointerList = null;
Expand Down
6 changes: 1 addition & 5 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ function connect () {
return Stack.connect()
}

function find (contentType = 'example') {
function find (contentType = 'blog') {
return Stack.contentType(contentType)
.entries()
.include([
'reference_single',
'reference_multiple'
])
.find()
}

Expand Down
36 changes: 30 additions & 6 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,8 @@ export class Stack {
this.q.except = keys
}

this.q.referenceDepth = this.q.referenceDepth || this.contentStore.referenceDepth
this.q.referenceDepth = (typeof this.q.referenceDepth === 'number') ? this.q.referenceDepth : this.contentStore
.referenceDepth

return {
filePath,
Expand Down Expand Up @@ -1289,12 +1290,24 @@ export class Stack {

for (let i = 0, j = oldShelf.length; i < j; i++) {
const element: IShelf = oldShelf[i]
let flag = true
for (let k = 0, l = result.docs.length; k < l; k++) {
if (result.docs[k].uid === element.uid) {
element.path[element.position] = result.docs[k]
flag = false
break
}
}

if (flag) {
for (let e = 0, f = oldShelf[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldShelf[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldShelf[i].path[e]).length === 2) {
(oldShelf[i].path as any).splice(e, 1)
break
}
}
}
}

// GC to avoid mem leaks!
Expand Down Expand Up @@ -1364,12 +1377,12 @@ export class Stack {

// tslint:disable-next-line: forin
for (const path in entryReferences) {
const idx = includePath.indexOf(path)
if (~idx) {
const subStr = includePath.slice(0, path.length)
if (subStr === path) {
let subPath
// Its the complete path!! Hurrah!
if (path.length !== includePath.length) {
subPath = includePath.slice(0, path.length)
subPath = subStr
pendingPath.push(includePath.slice(path.length + 1))
} else {
subPath = includePath
Expand All @@ -1380,8 +1393,7 @@ export class Stack {
_content_type_uid: this.types.content_types,
uid: entryReferences[path],
})
} else {

} else if (entryReferences[path].length) {
entryReferences[path].forEach((contentTypeUid) => {
schemasReferred.push({
_content_type_uid: this.types.content_types,
Expand Down Expand Up @@ -1636,12 +1648,24 @@ export class Stack {

for (let i = 0, j = oldObjectPointerList.length; i < j; i++) {
const element: IShelf = oldObjectPointerList[i]
let flag = true
for (let k = 0, l = result.docs.length; k < l; k++) {
if (result.docs[k].uid === element.uid) {
element.path[element.position] = result.docs[k]
flag = false
break
}
}

if (flag) {
for (let e = 0, f = oldObjectPointerList[i].path.length; e < f; e++) {
// tslint:disable-next-line: max-line-length
if (oldObjectPointerList[i].path[e].hasOwnProperty('_content_type_uid') && Object.keys(oldObjectPointerList[i].path[e]).length === 2) {
(oldObjectPointerList[i].path as any).splice(e, 1)
break
}
}
}
}
// GC to avoid mem leaks!
oldObjectPointerList = null
Expand Down

0 comments on commit e16480d

Please sign in to comment.